[英]Can't figure out why my Scrapy script isn't working
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 新手,所以问题可能很明显,但我无法弄清楚。
正如@Shahin 提到的,页面是动态生成的,如果没有 selenium 或 splash 之类的东西,您将无法解析它。 读这个。
还有另一种方法:您可以在生成请求的方式中进行一些搜索,这将为您提供所需的数据。
例如,当页面加载或进入底部时,向https://gql.twitch.tv/gql请求一些数据,请看下图:
这是请求将返回带有目录游戏描述的 json: 所以,我认为您只需要找出请求数据如何构建和发出请求,而不是
twitch.tv/directory
,而是gql.twitch.tv/gql
并解析 json 格式的响应。
如何在此处使用正文发出请求(有正文参数)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.