首页 > 解决方案 > 尽管在 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()

结果:

scraping_result_using_xpath_and_css 选择器

标签: python-3.xweb-scrapingxpathscrapycss-selectors

解决方案


你的定位器是错误的。
尝试这个:

countries = response.xpath('//table/tbody[2]/tr/td[1]/p/a')

推荐阅读