【问题标题】:Python Selenium Run All Page JavascriptsPython Selenium 运行所有页面 Javascript
【发布时间】:2014-04-25 20:15:26
【问题描述】:

我正在抓取使用 Google 自定义搜索 iframe 的网站。我正在使用 Selenium 切换到 iframe,并输出数据。我正在使用 BeautifulSoup 来解析数据等。

from bs4 import BeautifulSoup
from selenium import webdriver
import time
import html5lib

driver = webdriver.Firefox()

driver.get('http://myurl.com')
driver.execute_script()
time.sleep(4)
iframe = driver.find_elements_by_tag_name('iframe')[0]
driver.switch_to_default_content()
driver.switch_to_frame(iframe)

output = driver.page_source

soup = BeautifulSoup(output, "html5lib")

print soup

我成功进入 iframe 并获取“一些”数据。在数据输出的最顶部,它谈到启用 Javascript,以及重新加载页面等。我正在寻找的页面部分不存在(从我通过开发人员工具查看源代码时) .所以,很明显其中一些没有加载。

所以,我的问题 - 你如何让 Selenium 加载所有页面 javascripts?是自动完成的吗?

我在 SO 上看到很多关于运行单个函数等的帖子……但没有关于在页面上运行所有 JS 的帖子。

感谢任何帮助。

【问题讨论】:

    标签: python python-2.7 selenium


    【解决方案1】:

    啊,原来是在标签中出现了“必须启用Javascript”的文字。

    我刚刚在这里发布了一个关于如何在嵌套 iframe 内切换的问题:

    Python Selenum Swith into an iframe within an iframe

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-22
      • 2020-08-30
      • 1970-01-01
      • 1970-01-01
      • 2021-03-20
      • 1970-01-01
      • 2016-08-26
      相关资源
      最近更新 更多