Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-如何打开多个浏览器窗口并在这些窗口上运行选项卡?_Python_Windows_Selenium_Selenium Webdriver_Tabs - Fatal编程技术网

Python-如何打开多个浏览器窗口并在这些窗口上运行选项卡?

Python-如何打开多个浏览器窗口并在这些窗口上运行选项卡?,python,windows,selenium,selenium-webdriver,tabs,Python,Windows,Selenium,Selenium Webdriver,Tabs,我对python非常陌生,所以在这方面我是个新手,我尝试过搜索,但似乎没有任何效果(至少我所看到和测试过的)。我也尝试过“webbrowser.get(chrome_path).open(url)”,但并没有真正帮助我。不管怎样,这是密码 from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import

我对python非常陌生,所以在这方面我是个新手,我尝试过搜索,但似乎没有任何效果(至少我所看到和测试过的)。我也尝试过“webbrowser.get(chrome_path).open(url)”,但并没有真正帮助我。不管怎样,这是密码

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import webbrowser

#path for the driver
driver  = webdriver.Chrome(executable_path="C:\mydriver\chromedriver")

driver.get("https://www.google.com")
driver.execute_script("window.open ('https://www.google.com', 'new window')")
driver.switch_to.window(driver.window_handles[0])

driver.execute_script("window.open ('https://www.bing.com','https://www.facebook.com', 'new window')")
driver.switch_to.window(driver.window_handles[1])

Selenium是在浏览器中测试GUI的工具。从你的问题来看,听起来你只是想打开几个浏览器窗口。为什么不运行Chrome/IE/Firefox/。。。直接从Python中的命令行

导入子流程
Popen(“启动chrome/new tab www.google.com”,shell=True)

Selenium是一种在浏览器中测试GUI的工具。从你的问题来看,听起来你只是想打开几个浏览器窗口。为什么不运行Chrome/IE/Firefox/。。。直接从Python中的命令行

导入子流程
Popen(“启动chrome/new tab www.google.com”,shell=True)

您需要为每个新浏览器窗口初始化
webdriver
实例:

from selenium import webdriver

urls = ['https://www.google.com', 'https://www.facebook.com', 'https://www.twitter.com']
for url in urls:
    driver = webdriver.Chrome()
    driver.get(url)

您需要为每个新浏览器窗口初始化
webdriver
实例:

from selenium import webdriver

urls = ['https://www.google.com', 'https://www.facebook.com', 'https://www.twitter.com']
for url in urls:
    driver = webdriver.Chrome()
    driver.get(url)

是的,谢谢,但是我怎样才能用它打开一个单独的窗口呢?因为我在每个窗口上至少需要40个选项卡(说我决定总共有10个或更多窗口),所以我可以进去获取我的“数据”,因为等待每个选项卡加载到一个窗口上需要几个小时,所以在不同的选项卡上同时运行它们会大大减少时间。是的,谢谢,但我如何用它打开一个单独的窗口呢?因为我在每个窗口上至少需要40个选项卡(说我决定总共有10个或更多窗口),所以我可以进入并获取我的“数据”,因为等待每个选项卡加载到一个窗口上需要几个小时,所以在不同的选项卡上同时运行它们将大大减少时间。是的,这是一种足够的方法,但我需要打开多个选项卡,这样我就可以进入并获取我的“数据”,而不仅仅是一个指向新URL的选项卡,因为我需要减少时间,因为在一个窗口中打开400多个选项卡会花费大量时间,所以要减少时间,比如说,对于400个选项卡,我需要10个窗口的40个选项卡,同时在不同的选项卡上运行它们会减少。是的,这是一个足够的方法,但我需要打开多个选项卡,这样我才能进入并获取我的“数据”,而且不仅仅是一个标签指向一个新的URL,因为我需要减少时间,因为在一个窗口中打开400多个标签会花费很多时间,所以要减少时间,比如说,对于400个标签,我需要在10个窗口中使用40个标签,同时在不同的标签上运行它们会减少时间。