'How can I scrape a product price from a website using Beautifulsoup?
I'm trying to extract the latest bid price for this sneaker from StockX but I'm getting the error
IndexError: list index out of range
since sneaker_price
is coming up blank for some reason. Can anyone please help?:
from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://stockx.com/air-jordan-6-retro-travis-scott")
soup = BeautifulSoup(driver.page_source,"lxml")
driver.quit()
sneaker_price = soup.select("div.en-us stat-value stat-small")[0]
Solution 1:[1]
You can use the .ask div.en-us.stat-value.stat-small
selector to get the div containing the latest ask price. And since there is more than one element you can select the last one such as:
ask_price = soup.select('.ask div.en-us.stat-value.stat-small')[-1]
print(ask_price.text) # $655
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | FluidLight |