I am working on python program that after it gets ID of steam bundle - it returns the current price.
Program is using requests and lxml.
There are two paths for the final price:
- /html/body/div[1]/div[7]/div[4]/div[1]/div[2]/div/div[2]/div[10]/div[3]/div
- //*[@id="game_area_purchase"]/div/div/div/div[1]/div/div/div[2]
Using example: https://store.steampowered.com/bundle/16140
Here's a code:
import requests
import lxml.html
#example URL for steam bundle
URL = "https://store.steampowered.com/bundle/16140"
html = requests.get(URL)
doc = lxml.html.fromstring(html.content)
#xpath to price location
price = doc.xpath('/html/body/div[1]/div[7]/div[4]/div[1]/div[2]/div/div[2]/div[10]/div[3]/div/text()')
print(price)
Program returns this:
[]
or this
Traceback (most recent call last):
File <path-to-program>, line 9, in <module>
price = doc.xpath('/html/body/div[1]/div[7]/div[4]/div[1]/div[2]/div/div[2]/div[10]/div[3]/div/text()')[0]
IndexError: list index out of range
I get an error for both options. What should I do to fix it?