如何限制spider使用scrapy对某些xpath进行爬网

2024-09-26 22:50:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图抓取一个网站,从产品页面我试图报废产品说明,但我如何只选择产品说明:

link to page

xPath : hxs.select('//div[@class="product-shop"]/p/text()').extract()

HTML非常大,因此请查看上面指定的链接。。在

我只想选择产品描述而不是其他细节。。。在

如果我这样做:

^{pr2}$

但我只想要:

[u'This product is part of the Basics T.shirts line made of 100% Cotton. Stripes Muscle Fit T.shirts that come in Green Color. Casual that comes with Henley away.']

Tags: oftodivthat产品网站pagelink
1条回答
网友
1楼 · 发布于 2024-09-26 22:50:16

右键单击chrome中元素面板中的元素会告诉我:

enter image description here

//*[@id="product_addtocart_form"]/div[2]/div[1]/p[3]

指向

^{pr2}$

this page上尝试相同的XPATH也会指向其中的描述:

<p>This product is part of the Basics Shirts line made of 100% Cotton.<br>
                    Plain Slim Fit Shirts that come in Orange Color.<br>
                    Casual that comes with Button Down away.</p>

所以看起来你只需要在页面上调用XPATH就可以设置了。但是,您仍然应该验证XPATH在所有情况下都能正常工作,因为它总是很容易根据页面而变化。在

相关问题 更多 >

    热门问题