mysql构建url给scrapy_Python Scrapy从mysq填充起始url
我嘗試使用蜘蛛網.py。當我跑“小蜘蛛”的時候蜘蛛網.py“我沒有得到任何輸出,只是沒有出錯。在
我在python腳本中測試了SELECT查詢,并使用MYSQL表中的條目填充start_url。在
蜘蛛網.pyfrom scrapy.spider import BaseSpider
from scrapy.selector import Selector
import MySQLdb
class ProductsSpider(BaseSpider):
name = "Products"
allowed_domains = ["test.com"]
start_urls = []
def parse(self, response):
print self.start_urls
def populate_start_urls(self, url):
conn = MySQLdb.connect(
user='user',
passwd='password',
db='scrapy',
host='localhost',
charset="utf8",
use_unicode=True
)
cursor = conn.cursor()
cursor.execute(
'SELECT url FROM links;'
)
rows = cursor.fetchall()
for row in rows:
start_urls.append(row[0])
conn.close()
總結
以上是生活随笔為你收集整理的mysql构建url给scrapy_Python Scrapy从mysq填充起始url的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 函数参数前面两个星号_Py
- 下一篇: owdcloud mysql_MySQL