[英]How do i use XPATH properly in scrapy?
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 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
Above is the link of the page以上是页面的链接
: https://i.stack.imgur.com/8bhzV.png : https://i.stack.imgur.com/8bhzV.png
The red marked box number is what I am trying to get through xpath红色标记的框号是我试图通过 xpath 获得的
: https://i.stack.imgur.com/mca05.png : https://i.stack.imgur.com/mca05.png
The red marked box is the inspect line of that same item.红色标记的框是同一项目的检查行。 my code is below我的代码在下面
**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.)
when is use view(response) it says true & opens the same page in browser.什么时候使用 view(response) 它说 true & 在浏览器中打开相同的页面。
My code is below我的代码在下面
: https://i.stack.imgur.com/YAf38.png : https://i.stack.imgur.com/YAf38.png
: https://i.stack.imgur.com/fTWwH.png : https://i.stack.imgur.com/fTWwH.png
When you say get end of the xpath you will print what you expect also I update your xpath too:当您说结束 xpath 时,您将打印您期望的内容,我也会更新您的 xpath:
instead this:取而代之的是:
assetid = response.xpath("//div[3]/center/table[2]/tbody/tr[4]/td[2]")
use this:用这个:
assetid = response.xpath('//table[2]//tr[4]/td[2]/text()').get()
I hope it will works.我希望它会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.