【发布时间】:2018-06-01 03:22:54
【问题描述】:
我在 python 中结合 selenium 编写了一个脚本来解析网页中的一些项目。无论如何我无法让它工作。我追求的项目(也许)在iframe 内。我试图切换它,但没有任何效果。除了TimeoutException 到达我试图切换iframe 的行时,我什么也得不到。我怎样才能让它工作。提前致谢:
这里是网页链接:URL
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
url = "replace_with_above_url"
driver = webdriver.Chrome()
driver.get(url)
wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "tradingview_fe623")))
for item in wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".quick .apply-common-tooltip"))):
print(item.text)
driver.quit()
我所追求的项目所在的元素:
<div class="quick">
<span class="apply-common-tooltip">5</span>
<span class="apply-common-tooltip">1h</span>
<span class="apply-common-tooltip selected">1D</span>
<span class="apply-common-tooltip">1M</span>
<span class="apply-common-tooltip">1D</span>
</div>
这是我期望的输出(当我尝试使用 css 选择器获取它们时它在本地工作):
5
1h
1D
1M
1D
这是它在网络上的样子:
【问题讨论】:
标签: python python-3.x selenium selenium-webdriver web-scraping