Scrapy 教程的代码错误
Code Error with Scrapy Tutorial
我正在尝试学习 Scrapy 并学习基础知识 tutorial.I 我正在使用 Anaconda Navigator。我在安装了 scrapy 的环境中工作。我已经输入了代码,但一直出现错误。
代码如下:
import scrapy
class FirstSpider(scrapy.Spider):
name = "FirstSpider"
def start_requests(self):
urls = [
'http://quotes.toscrape.com/page/1/',
'http://quotes.toscrape.com/page/2/',
]
for url in urls:
yield scrapy.Requests(url=url, callback = self.parse)
def parse(self, response):
page = response.url.split("/")[-2]
filename = "quotes-%.html" % page
with open(filename, "wb") as f:
f.write(response.body)
self.log("saved file %s")% filename
代码运行了一会儿。说它抓取了 0 个页面。然后DEBUGS: Telnet Console,然后出这个错误,"[scrapy.core.engine] ERROR: Error while obtaining start requests."
代码然后又运行了一些,然后又出现了另一个错误,"yield scrapy.Requests(utl=url, callback = self.parse)" that says "AttributeError: Module 'scrapy' has no attribute 'Requests'.
我重写了代码,并寻找答案。请帮忙。谢谢!
这里有错字:
yield scrapy.Requests(url=url, callback = self.parse)
是 Request
而不是 Requests
。
我正在尝试学习 Scrapy 并学习基础知识 tutorial.I 我正在使用 Anaconda Navigator。我在安装了 scrapy 的环境中工作。我已经输入了代码,但一直出现错误。
代码如下:
import scrapy
class FirstSpider(scrapy.Spider):
name = "FirstSpider"
def start_requests(self):
urls = [
'http://quotes.toscrape.com/page/1/',
'http://quotes.toscrape.com/page/2/',
]
for url in urls:
yield scrapy.Requests(url=url, callback = self.parse)
def parse(self, response):
page = response.url.split("/")[-2]
filename = "quotes-%.html" % page
with open(filename, "wb") as f:
f.write(response.body)
self.log("saved file %s")% filename
代码运行了一会儿。说它抓取了 0 个页面。然后DEBUGS: Telnet Console,然后出这个错误,"[scrapy.core.engine] ERROR: Error while obtaining start requests."
代码然后又运行了一些,然后又出现了另一个错误,"yield scrapy.Requests(utl=url, callback = self.parse)" that says "AttributeError: Module 'scrapy' has no attribute 'Requests'.
我重写了代码,并寻找答案。请帮忙。谢谢!
这里有错字:
yield scrapy.Requests(url=url, callback = self.parse)
是 Request
而不是 Requests
。