class EastSpider(scrapy.Spider):
name = 'East'
allowed_domains = ['****.com']
start_urls = ['http://finance.***.com/news.html'] def parse(self, response):
nextUrl = response.xpath('//*[contains(@class,"page-btn")]/@href') for url in nextUrl.extract():
time.sleep(1) yield Request(urljoin(response.url,url))
contentUrl = response.xpath('//p[@class="title"]/a/@href') for urls in contentUrl.extract():
time.sleep(1) yield Request(urls,callback = self.parse)
pass代碼如上,但是在命令行運行scrapy crawl East -o East.csv的結果,East.csv是個空文件,什么都沒寫進去。我看人家說要yield,但是自己搞了搞也沒行...嘗試了在for循環之外添加yield url、yield urls報錯,說是在定義之前引用了,然后在for循環之內添加又沒效果,還是空文件...
添加回答
舉報
0/150
提交
取消