我正试图使用start_url spider.py从MYSQL表中填充一个SELECT。当我运行“刮伤运行蜘蛛spider.py”时,我没有得到任何输出,只是它没有出现错误。
我已经在python脚本中测试了SELECT查询,并且用MYSQL表中的entrys填充了start_url。
spider.py
from 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()https://stackoverflow.com/questions/20118753
复制相似问题