I'm trying to make a program that will keep checking the HTML of this page: https://www.walmart.com/ip/Sony-PlayStation-5-PS5-Digital-Edition/607045762 to see if the PS5 is "in stock" or not.
I found by using inspect element that there is an element which says <link itemprop="availability" href="//schema.org/InStock" tabindex="-1">
So I know that if I can search the HTML for this tag, and make sure it says "InStock" I can find out if it is in stock.
The problem is when I try getting the HTML of the page using requests or urllib, I get something that starts with <html lang="en">
and ends with </html>
and in between is just a bunch of CSS and styling. It doesn't have what I was looking for and the tags like the one mentioned above aren't anywhere to be found. I would also be fine with seeing the text that says
Free delivery Arrives by Wed, Sep 8
but my HTML doesn't have that either. Am I doing this wrong? I'm using PyCharm.
Here is the code I have right now:
import urllib.request
myrequest = urllib.request.urlopen("https://www.walmart.com/ip/Sony-PlayStation-5-PS5-Digital-Edition/607045762")
my_HTML = my_request.read().decode("utf8")
print(my_HTML)
Edit: I tried using Selenium with this code:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:39.0) Gecko/20100101 Firefox/39.0')
browser = webdriver.Chrome(options = options)
browser.set_page_load_timeout(30)
browser.get('https://www.walmart.com/ip/Sony-PlayStation-5-PS5-Digital-Edition/607045762')
all_links = browser.find_element_by_tag_name("link")
all_links = [i.text for i in all_links]
print(all_links)
browser.close()
When I do this I get a bunch of traceback errors.
FileNotFoundError: [WinError 2] The system cannot find the file specified
and
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Is this incorrect code?