I am grabbing a value from url source page by xpath. but this is not existed. so I want to pass the requests and try to grab that value again: what I tried:
import requests
from lxml import html
url='http://www.example.com'
cont=requests.get(url)
tree=html.fromstring(cont)
out=tree.xpath('...')[0]
When I run it I have the following Error:
IndexError: list index out of range
How can I request for grabbing value again in this case?
update
I know this error means xpath doesn't exist. so I want to request to that url to grab xpath again.
Use Try Except
Or if you wanna do it forever until you get the right one: