css - 下一页链接的 CSS 选择器在 Scrapy shell 中返回空列表
问题描述
我是 Scrapy 的新手。我尝试从该站点获取指向下一页的链接https://book24.ru/knigi-bestsellery/?section_id=1592
html 是什么样子的:在此处输入图像描述
在scrapy shell中我写了这个命令:
response.css('li.pagination__button-item._next a::attr(href)')
它返回一个空列表。
我也试过
response.css('a.pagination__item._link._button._next.smartLink')
但它也返回一个空列表。
我将不胜感激!
解决方案
该页面是使用 JavaScript 生成的,使用“view(response)”查看它的外观。
# with css:
In [1]: response.css('head > link:nth-child(28) ::attr(href)').get()
Out[1]: 'https://book24.ru/knigi-bestsellery/page-2/'
# with xpath:
In [2]: response.xpath('//link[@rel="next"]/@href').get()
Out[2]: 'https://book24.ru/knigi-bestsellery/page-2/'
推荐阅读
- java - java不兼容类型T不能转换为Enum
- laravel - laravel 站点地图和转换为 xml
- postgresql - 我可以全局授予对 postgres 中视图的访问权限吗
- ruby-on-rails - 如何测试关联属性的唯一性
- c# - 建议一个静态类作为另一种类型属性的值源
- file - 从 CMD Out-File 运行 PS1 时无法访问文件
- function - 出现“发生服务器错误。请再次尝试保存项目。(线 0)。在正常工作的脚本上
- git - 恢复远程分支上的提交
- php - api.weather.gov 开始和结束时间
- c++ - Visual Studio 代码 C++ 中的子文件夹