0

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())"))

Error

2 Answers 2

1

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+"']();"))
Sign up to request clarification or add additional context in comments.

2 Comments

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?
Date.UTC(2007,11,19) is the number of seconds after January 1 1970 until December 19 2007.
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.