python - 读取从 selenium 检索到的 soup 中的 html 源代码

标签 python selenium beautifulsoup

driver = webdriver.Firefox()
driver.maximize_window()
driver.get(url)
html_source=driver.page_source   
html = BeautifulSoup(html_source)

为什么 html_source 和 html 不同。我在这里做错了什么?

最佳答案

driver.get 与大多数其他 get 方法不同,您只访问页面。然后,您可以使用 driver.page_source 获取 html:

driver = webdriver.Firefox()
driver.maximize_window()
driver.get(url)
soup = BeautifulSoup(driver.page_source)

关于python - 读取从 selenium 检索到的 soup 中的 html 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31059640/

相关文章:

python - 是列表[i :j] guaranteed to be an empty list if list[j] precedes list[i]?

python - 在Docker容器中的 headless Chrome中使用python中的Selenium

python - 从提取的链接中去除 html 标签

python - 抓取并比较网页数据

python - 按标签顺序对 html 内容进行分组

python - 在python中获取给定周数的第一天和最后一天

python - 使用一系列值及其频率作为字典绘制直方图

python-3.x - 即使在 chromedriver 之后,Chrome 也会随机崩溃

python - 模拟返回模拟对象而不是返回值

java - Selenium RC 并点击面板链接!