I wanted to retrieve a variable named "stats" from the site https://csgostats.gg/player/76561198087162515 using Selenium with Python with the following code:
browser = webdriver.Chrome()
browser.get("https://csgostats.gg/player/76561198087162515")
stats = browser.execute_script("return stats")
print(stats)
However, the console returns an error saying "match is not defined". When I use inspect element on the site, I can clearly see the stats variable as shown here: stats variable inside script tag
Does anyone know what I might be doing wrong here? The code I'm using seems to work for variables from other websites so I'm not sure what I'm doing wrong. I'm pretty new to this stuff so any help would be appreciated, thanks!
statsvariable. See here: stackoverflow.com/a/51780317/7253453 -- you would need to dosoup = BeautifulSoup(browser.page_source, 'lxml')to parse the HTML of the webpage. Not as elegant, but a workable solution nonetheless.get()the page? Or were you usingrequests. If it is the latter, that's likely the reason, asrequests.get()is not javascript enabled, whereasselenium.get()is. You'll want to.get()the page with selenium, then parse the.page_sourcewith BeautifulSoup