本文共 646 字,大约阅读时间需要 2 分钟。
我尝试使用蜘蛛网.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()
转载地址:https://blog.csdn.net/weixin_33443932/article/details/113953397 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!