返回信息流参照scrapy的第一个例程:
import scrapy
class DmozSpider(scrapy.spiders.Spider):
name = "dmoz"
allowed_domains = ["dmoz.org"]
start_urls = [
"http://www.dmoz.org/Computers/Programming/Languages/Python/Books/",
"http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/"
]
def parse(self, response):
filename = response.url.split("/")[-2]
with open(filename, 'wb') as f:
f.write(response.body)
楼主想要实现一个类似的网站抓取系统,就是strat_urls是可以接受用户输入的,而不是写死在程序里面的,请问各位有什么好的办法么?
这是一条镜像帖。来源:北邮人论坛 / python / #12844同步于 2016/3/23
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖
[问题]Scrapy爬取得网站可以不用写死在程序里面么?
yuankaiqi
2016/3/23镜像同步1 回复
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
直接使用Request http://scrapy-chs.readthedocs.org/zh_CN/latest/topics/request-response.html
class scrapy.http.Request(url[, callback, method='GET', headers, body, cookies, meta, encoding='utf-8', priority=0, dont_filter=False, errback])