使用selenium返回动态页面的html代码

时间:2015-06-17 12:28:20

标签: python python-2.7 selenium selenium-webdriver web-scraping

我正在尝试抓取这个网站,问题是它是否已动态加载。

基本上我想要从浏览器控制台看到的内容,而不是我在右键单击时看到的内容>显示消息来源。

我尝试了一些硒的例子,但我无法得到我需要的东西。下面的代码使用selenium,只获取右键单击的内容 - >显示代码。如何获取加载页面的内容?

0xa8

1 个答案:

答案 0 :(得分:1)

在获取网页来源之前,您需要明确等待搜索结果显示

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC


wd = webdriver.Firefox()
wd.get("https://www.leforem.be/particuliers/offres-emploi-recherche-par-criteres.html?exParfullText=&exPar_search_=true&    exParGeographyEdi=true")

wd.switch_to.frame("cible")

wait = WebDriverWait(wd, 10)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'td.resultatIntitule')))

print(wd.page_source)