problem with executing the script from page
here is the page HTML : HTML
and here is the code
pprint(wd.execute_script("return getChartInitJsCode_5f9462fb094a4()"))
the complete code is:
from selenium import webdriver
from pprint import pprint
options = webdriver.ChromeOptions()`
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome(options=options)
wd.get("https://www.collectorsquare.com/en/watches/breitling/navitimer/lpi")
pprint(wd.execute_script("return (getChartInitJsCode_5f9462fb094a4())"))
2 Answers 2
It was a dynamically generated class so here is the proper way to grab it. It should work through any changes it does now.
name=wd.find_element_by_css_selector("div.lpi-chart-container").get_attribute('data-chart-init-code-function-name')
pprint(wd.execute_script("return window['"+name+"']();"))
answered Oct 25, 2020 at 2:08
Arundeep Chohan
9,9995 gold badges17 silver badges36 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
hagay jivilik
the data on the site is like this: [Date.UTC(2007,11,19),19738.00], but instead I get [1198022400000, 19738] can't read the date, any suggestions?
Arundeep Chohan
Date.UTC(2007,11,19) is the number of seconds after January 1 1970 until December 19 2007.
The function name is variable, you need to get the right one each time:
import re
r = re.findall(r'function (getChartInitJsCode[^(]+)', wd.page_source)
if r:
pprint(wd.execute_script("return (%s())" % r[0]))
Comments
Explore related questions
See similar questions with these tags.