我如何在 scrapy 中正确使用 XPATH?
How do i use XPATH properly in scrapy?
以上是页面link
: https://i.stack.imgur.com/8bhzV.png
红色标记的框号是我试图通过xpath得到的
: https://i.stack.imgur.com/mca05.png
红色标记框是同一项目的检查线。我的代码如下
**scrapy shell**
**fetch("http://mnregaweb4.nic.in/netnrega/asset_report_dtl.aspx?lflag=eng&state_name=WEST%20BENGAL&state_code=32&district_name=NADIA&district_code=3201&block_name=KRISHNAGAR-I&block_code=&panchayat_name=DOGACHI&panchayat_code=3201009009&fin_year=2020-2021&source=national&Digest=8+kWKUdwzDQA1IJ5qhD8Fw")**
**assetid = response.xpath("//div[3]/center/table[2]/tbody/tr[4]/td[2]")**
**assetid**
**[]**(This is what it returns.)
**assetid = response.xpath("//div[3]/center/table[2]/tbody/tr[4]/td[2]/text()")**(I tried this also)
**assetid**
**[]**(This is what it returns.)
何时使用 view(response) 它说 true 并在浏览器中打开相同的页面。
我的代码如下
: https://i.stack.imgur.com/YAf38.png
: https://i.stack.imgur.com/fTWwH.png
当您说结束 xpath 时,您将打印您期望的内容,我也更新了您的 xpath:
改为:
assetid = response.xpath("//div[3]/center/table[2]/tbody/tr[4]/td[2]")
使用这个:
assetid = response.xpath('//table[2]//tr[4]/td[2]/text()').get()
希望有用。
以上是页面link
: https://i.stack.imgur.com/8bhzV.png
红色标记的框号是我试图通过xpath得到的
: https://i.stack.imgur.com/mca05.png
红色标记框是同一项目的检查线。我的代码如下
**scrapy shell**
**fetch("http://mnregaweb4.nic.in/netnrega/asset_report_dtl.aspx?lflag=eng&state_name=WEST%20BENGAL&state_code=32&district_name=NADIA&district_code=3201&block_name=KRISHNAGAR-I&block_code=&panchayat_name=DOGACHI&panchayat_code=3201009009&fin_year=2020-2021&source=national&Digest=8+kWKUdwzDQA1IJ5qhD8Fw")**
**assetid = response.xpath("//div[3]/center/table[2]/tbody/tr[4]/td[2]")**
**assetid**
**[]**(This is what it returns.)
**assetid = response.xpath("//div[3]/center/table[2]/tbody/tr[4]/td[2]/text()")**(I tried this also)
**assetid**
**[]**(This is what it returns.)
何时使用 view(response) 它说 true 并在浏览器中打开相同的页面。
我的代码如下
: https://i.stack.imgur.com/YAf38.png
: https://i.stack.imgur.com/fTWwH.png
当您说结束 xpath 时,您将打印您期望的内容,我也更新了您的 xpath:
改为:
assetid = response.xpath("//div[3]/center/table[2]/tbody/tr[4]/td[2]")
使用这个:
assetid = response.xpath('//table[2]//tr[4]/td[2]/text()').get()
希望有用。