【发布时间】:2017-10-31 21:10:55
【问题描述】:
import scrapy
class TestSpider(scrapy.Spider):
name = 'test'
start_urls = ['https://go.twitch.tv/directory']
def parse(self, response):
for title in response.css('body'):
yield {'title': title.css('h3.tw-box-art-card__title::text').extract()}
for next_page in response.css('a::attr(href)'):
yield response.follow(next_page, self.parse)
它只是抓取和抓取https://go.twitch.tv/directory,但不输出任何标题。
我是 Python 新手,所以问题可能很明显,但我无法弄清楚。
【问题讨论】:
-
您为什么希望您的代码显示任何标题?
-
因为解析函数和我用来运行脚本的命令“scrapy crawl test -o test.csv
-
您的代码缩进严重。修复它,您可能会发现它很有帮助。
-
@Massaxe
parse是否真的被调用了? -
@Massaxe ,该网页的内容是动态生成的,因此您需要使用任何浏览器模拟器,例如 selenium。
标签: python web-scraping scrapy web-crawler scrapy-spider