我对使用scrapy进行网页抓取是新手。我试图刮一个网站(请参考代码中的网址)。 从网站上,我试图删除'notification For%Month%%Year%'表下的信息,并将数据传输到json文件中。在
I am getting an error as "'NoneType' object is not iterable",while executing the command:
scrapy crawl quotes -o quotes.json
代码:
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes"
def start_requests(self):
urls = [
'http://www.narakkalkuries.com/intimation.html#i'
]
def parse(self, response):
for check in response.xpath('//table[@class="MsoTableGrid"]'):
yield{
'data':check.xpath('//table[@class="MsoTableGrid"]/tr/td/p/b//text()').extract_first()
}
问题: 在网站中,所有的提示数据都存储在同名的表下表@类=“MsoTableGrid”。在
选项是我试图提取数据
Option1
response.xpath('//table[@class="MsoTableGrid"]').extract()
Return all the data
选项2
response.xpath('//table[@class="MsoTableGrid"]/tr[i]/td/p/b').extract()
Return few of the vertical column
选项3
response.xpath('//table[@class="MsoTableGrid"]/tr/td/p/b//text()').extract()[1]
Return first element from the whole data
问题:
要添加到这一点,
start_requests
应该是scrapy.Request
对象的生成器。您的start_requests
没有产生任何结果:要修复在
^{pr2}$start_requests
方法中逐个生成URL的问题:或者只需设置
start_urls
class属性,就可以使用从scrapy.Spider
继承的默认start_requests
方法:相关问题 更多 >
编程相关推荐