【发布时间】:2019-01-22 07:51:10
【问题描述】:
我是 selenium python 网络抓取的初学者。我正在尝试抓取显示各种药物年度价格的数据。但是我收到一条错误消息:
Traceback(最近一次调用最后一次): 文件“other.py”,第 11 行,在 路径 = WebDriverWait(d,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".highcharts-grid highcharts-yaxis-grid path"))) 文件“wait.py”,第 80 行,直到 引发 TimeoutException(消息、屏幕、堆栈跟踪) selenium.common.exceptions.TimeoutException:消息:
我不确定我必须做什么。我到目前为止的代码是:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
url = 'http://abacus.realendpoints.com/ConsoleTemplate.aspx?act=qlrd&req=nav&mop=abacus!main&pk=ed5a81ad-9367-41c8-aa6b-18a08199ddcf&ab-eff=1000&ab-tox=0.1&ab-nov=1&ab-rare=1&ab-pop=1&ab-dev=1&ab-prog=1.0&ab-need=1&ab-time=1543102810'
d = webdriver.Chrome()
actions = ActionChains(d)
d.get(url)
paths = WebDriverWait(d,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".highcharts-grid highcharts-yaxis-grid path")))
results = []
for path in paths:
actions.move_to_element(path).perform()
actions.click_and_hold(path).perform()
items = d.find_elements_by_css_selector('#priceChart path + text tspan')
result = [item.text for item in items]
if result:
results.append(result)
d.close()
print(results)
【问题讨论】:
-
请将完整的 Traceback 错误添加到您的问题中。
-
您尝试自动化的手动步骤是什么?
-
我正在尝试提取页面顶部每种药物的年度价格。仅当您将鼠标悬停在每个分隔的矩形上时,价格才会出现
-
不,不是。我不知道我的错误是什么