我正在进行远程网络抓取和抓取,并希望不要为一页上的每个链接重新加载新的浏览器窗口。
问题是我的 Firefox Web 驱动程序没有打开新标签。
这是我尝试过的:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from pyvirtualdisplay import Display
# launch our headless display
display = Display(visible=0, size=(800, 600))
display.start()
# launch our web driver and get a page
browser = webdriver.Firefox()
browser.get("http://www.google.com/")
# try to open a new tab
ActionChains(browser).key_down(Keys.CONTROL).send_keys("t").key_up(Keys.CONTROL).perform()
# this should print 2, but it prints 1, because new tab not opened
print len(browser.window_handles)
# clean up everything
browser.quit()
display.stop()
规格:
- Ubuntu 14.04.2
- Python 2.7.6
- 硒 2.47.1
- PyVirtualDisplay 0.1.3