我正在编写一个 Python 脚本来一次打开多个网页,然后进行搜索。 Python 会一个接一个地打开它们,但速度非常慢。我在 Chrome 中打开了 12 个选项卡。 这是我用来在 Chrome 中每个网站的新标签页中打开网站的代码。有什么建议么? (使用 PyCharm,Python 3.5)
driver.get('https://www.website1.com')
driver.execute_script("window.open('');") # opens new tab
driver.switch_to.window(driver.window_handles[1])
driver.get('website2.com')
driver.execute_script("window.open('');") # opens new tab
driver.switch_to.window(driver.window_handles[2])
driver.get('website3.com')
最佳答案
我是新手,但我希望这对您的问题有所帮助。这将打开一个窗口,然后在该窗口中打开选项卡。
import webbrowser
url = 'http://website1.com'
url_1 = 'http://website2.com'
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
webbrowser.get(chrome_path).open(url)
webbrowser.get(chrome_path).open(url_1)
如何让它打开一个新的浏览器,因为我无法让 open_new()
工作。
import webbrowser
import os
url = 'http://python.org/'
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
os.startfile('C:/Program Files (x86)/Google/Chrome/Application/chrome.exe', "open")
webbrowser.get(chrome_path).open_new(url)
webbrowser.get(chrome_path).open(url + '/doc')
关于Python-是否可以一次打开多个 Chrome 网页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52065455/