Hi,
I am trying to scrape the price of an item from an online store. The code works with sites such as ebay.com, amazon.com etc. and many others but is not working in some cases. I am using lxml and I am providing the xpath obtained using selector gadget. The code can be seen below.
I appreciate the cooperation of forum members.
I am trying to scrape the price of an item from an online store. The code works with sites such as ebay.com, amazon.com etc. and many others but is not working in some cases. I am using lxml and I am providing the xpath obtained using selector gadget. The code can be seen below.
import requests from lxml import html pagecontent=requests.get("https://www.myntra.com/watches/fossil/fossil-women-rose-gold-toned-dial-watch-es3352i/759168/buy") tree = html.fromstring(pagecontent.content) data=tree.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "pdp-price", " " ))]') print(data[0].text);Here is the error. It can be understood from the error that data is an empty array. I would like to know how I can resolve this issue.
Error:Traceback (most recent call last):
File "scrape-test.py", line 7, in <module>
print(data[0].text);
IndexError: list index out of range
Version information: python 3.4.3I appreciate the cooperation of forum members.