【发布时间】:2020-07-10 12:49:37
【问题描述】:
我正在尝试从两个不同的网站上抓取 highcharts, 我在这个 stackoverflow 问题中遇到了这个 execute_script 答案: How to scrape charts from a website with python?
它帮助我从第一个网站上抓取,但是当我在第二个网站上使用它时,它返回以下错误:
line 27, in <module>
temp = driver.execute_script('return window.Highcharts.charts[0]'
selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot read
property '0' of undefined
网站是: http://lumierecapital.com/#
您应该单击左侧的性能按钮以获取高图。
目标:我只想从中获取日期和每单位资产净值
和上一个网站一样,这段代码应该打印出一个以 X 和 Y 作为键、日期和数据作为值的字典,但它不适用于这个。
这是python代码:
from bs4 import BeautifulSoup
import requests
from selenium.webdriver.chrome.options import Options
from shutil import which
from selenium import webdriver
import time
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_path = which("chromedriver")
driver = webdriver.Chrome(executable_path=chrome_path, options=chrome_options)
driver.set_window_size(1366, 768)
driver.get("http://lumierecapital.com/#")
performance_button = driver.find_element_by_xpath("//a[@page='performance']")
performance_button.click()
time.sleep(7)
temp = driver.execute_script('return window.Highcharts.charts[0]'
'.series[0].options.data')
for item in temp:
print(item)
【问题讨论】:
标签: python selenium web-scraping highcharts