python-3.x - 尽管在 scrapy 框架中传递了正确的路径值,但 response.xpath 或 response.css 没有返回任何结果
问题描述
我正在尝试从https://www.moneycontrol.com/markets/indian-indices/抓取一些数据。但是,我坚持以下步骤,尽管我提供了正确的 xpath 值,但它不会返回任何结果。任何帮助表示赞赏。
countries = response.xpath('//*[@id="indices_stocks"]/div[2]/div/div/div/div[2]/table/tbody[2]/tr/td[1]/p/a/text()').getall()
countries = response.css('#indices_stocks > div.indices > div > div > div > div.pinned > table > tbody:nth-child(2) > tr > td:nth-child(1) > p > a::text').getall()
结果:
解决方案
你的定位器是错误的。
尝试这个:
countries = response.xpath('//table/tbody[2]/tr/td[1]/p/a')
推荐阅读
- swift - 为什么我的循环网络请求无法在我的 SwiftUI 代码中下载相同数量的项目?
- django - 变量内的Django模板html变量
- android - 无法在 Emulator Android API 31 上安装应用程序。原因是安装错误:INSTALL_PARSE_FAILED_MANIFEST_MALFORMED?
- flutter - 与 android 相比,iOS 中的 HTTP GET 和 POST 非常慢
- numpy - Python numpy:np.float64 有多少位?
- python - 我如何操作数据框 - Python
- reporting-services - 如何将来自不同查询的字段添加到 SRSS 报表生成器中表的不同列中?
- postgresql - pg_dump 工具是否导出死元组
- android - 如何在解析云代码功能中获取用户 ID?
- windows - 需要一种转换 .RAR 的方法,包括嵌入式 .RAR(如果存在)