Scrambling text with xpath / lxml

I am trying to clear the text "2005-2013" from the text that says "drink between: 2005 - 2013" from http://www.cellartracker.com/wine.asp?iWine=91411 using xpath / lxml and I can do this only for some of the other pages on this site, not for this. Not sure what I am doing wrong / if the xpath I copied from the element is wrong

tell me:

print(content_divs[0].text_content().strip())
IndexError: list index out of range

      

Here's my code:

import requests, lxml.html
page = requests.get('http://www.cellartracker.com/wine.asp?iWine=91411')
html = lxml.html.fromstring(page.content)
content_divs = html.xpath('//*[@id="wine_copy_inner"]/p/a[4]')
print(content_divs[0].text_content().strip())

      

thank you for your help!!!

+3


source to share


2 answers


If you want to get "2005 - 2013"

you can use below code



content = html.xpath('//a[@title="Source: Community"]/text()')

      

0


source


Is the xpath index a zero index?

//*[@id="wine_copy_inner"]/p/a[4]

should be ...[3]

.



It looks like the number of tags a

changes on login and not in the log. You might want to use a different method to find this tag.

0


source







All Articles