mysql构建url给scrapy_Python Scrapy从mysq填充起始url
发布日期:2021-06-24 14:44:55 浏览次数:4 分类:技术文章

本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:owdcloud mysql_MySQL在Ubuntu远程配置
下一篇:python类属性初始化_Python类定义、属性、初始化和析构

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年03月29日 06时32分31秒