user1082471
user1082471

Reputation: 9

select xpath of data in a tag using lxml

I am trying to select the "(6)" in the tag below:

<a class="itemRating" href="http://www.newegg.com/Product/ProductReview.aspx?Item=N82E16834200347" title="Rating + 4">
<span class="eggs r4">&nbsp;</span>
(6)
</a>

The xpath, which I will call review, is in the () below:

review = site.xpath('/html/body/div[3]/div[2]/table/tr/td[2]/div/div[8]/div/div/div/a[3]

When I try printing review[0].text, it prints 'None' instead of the (6).

Any ideas?

Upvotes: 0

Views: 279

Answers (2)

reclosedev
reclosedev

Reputation: 9512

You can use:

review[0].text_content().strip()

or

review[0].xpath('string()').strip()

And I'd write your xpath as:

review = site.xpath('//a[@class="itemRating"]')

Upvotes: 0

jfs
jfs

Reputation: 414335

(6) is in the tail of <span> element:

>>> a[0].tail
'\n(6)\n'

Upvotes: 3

Related Questions