如何一次捕获多个div/表
我使用 Scrapy 的网址如下:
http://www.marzetti.com/products/marzetti/detail.php?bc=35&cid=2&pid=1101&i=pl
我需要在同一个中捕获scrapy item,如下:
/html/body/div/div[2]/table/tbody/tr[3]/td[4]/table/tbody/tr/td/div[2]/table/tbody/tr[2]/td[2] /div[4]
/html/body/div/div[2]/table/tbody/tr[3]/td[4]/table/tbody/tr/td/div[2]/table/tbody/tr[2]/td[2]/div[4]`
所以这是我的代码片段:
hxs = HtmlXPathSelector(response)
sites = hxs.select('/html/body/div/div[2]/table/tr[3]/td[4]/table/tr')
items = []
for site in sites:
..............
item['description'] = site.select('td/div[2]/table/tr[2]/td[2]/div[4] or div[5]//text()').extract()
但是,这会返回一个布尔答案,例如“description = True”,而我需要的是两个 div 中的实际文本。
欢迎任何建议。谢谢。 -TM
I am using Scrapy with the following url:
http://www.marzetti.com/products/marzetti/detail.php?bc=35&cid=2&pid=1101&i=pl
I need to capture in the same scrapy item, the following:
/html/body/div/div[2]/table/tbody/tr[3]/td[4]/table/tbody/tr/td/div[2]/table/tbody/tr[2]/td[2] /div[4]
/html/body/div/div[2]/table/tbody/tr[3]/td[4]/table/tbody/tr/td/div[2]/table/tbody/tr[2]/td[2]/div[4]`
So here's my code snippet:
hxs = HtmlXPathSelector(response)
sites = hxs.select('/html/body/div/div[2]/table/tr[3]/td[4]/table/tr')
items = []
for site in sites:
..............
item['description'] = site.select('td/div[2]/table/tr[2]/td[2]/div[4] or div[5]//text()').extract()
However, this returns a Boolean answer such as 'description = True', whereas what I need is the actual text within the two divs.
Any suggestions welcome. Thanks.
-TM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用标准 XPath 联合运算符“|”:
Use the standard XPath union operator '|' :