开发者

How to capture a number of divs/ tables at once

开发者 https://www.devze.com 2023-04-02 07:28 出处:网络
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 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/开发者_如何学Ctd/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


Use the standard XPath union operator '|' :

  (td/div[2]/table/tr[2]/td[2]/div[4]
| 
   div[5])
          //text()
0

精彩评论

暂无评论...
验证码 换一张
取 消