Python:在动态生成的HTML中查找内容

时间:2018-07-09 16:03:26

标签: python html selenium web-scraping beautifulsoup

我正在尝试根据系列代码(例如FMM1)从this website获取股票期权价格,但是该内容是在页面加载后动态生成的,并且我的python硒脚本无法提取正确的源代码,因此找不到它。当我检查元素时,I can find it,而不是当我单击“查看源代码”时。

这是我的代码:

# Here, we open the website for options prices in Chrome
driver = webdriver.Chrome()
driver.get("http://www.bmfbovespa.com.br/pt_br/servicos/market-data/consultas/mercado-de-derivativos/precos-referenciais/precos-referenciais-bm-f-premios-de-opcoes/")

# Since the page is populated by JavaScript code *after* loading the page, we 
# tell the browser to wait 10 seconds before getting the source html code
time.sleep(10)
html_file = driver.page_source # gets the html source of the page
print(html_file)

我也尝试了以下方法,但是没有用:

WebDriverWait(driver, 60).until(EC.visibility_of_element_located((By.ID,
              "divContainerIframeBmf")))

1 个答案:

答案 0 :(得分:0)

在页面加载后使用它

THREE.RawShaderMaterial

,然后继续在页面上执行操作。