【发布时间】: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