如何打开 20+使用 webDriver (python) 在 chrome 中打开窗口
我想用一个驱动程序同时打开 20 个或 10 个以上选项卡..如果我使用 for 循环..它只是打开但关闭现有的并且我不知道为什么我认为我犯了一些错误.. 我想知道这些事情.. 1. 打开不同的窗口 2. 不应该崩溃 3. 需要输入 diff diff 值
我的代码:
def start():
options = webdriver.ChromeOptions()
options.add_argument(
"user-data-dir=C:\\Users\\rohit\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
options.add_experimental_option("useAutomationExtension", False)
options.add_experimental_option(
"excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--disable-blink-features=AutomationControlled")
# options.add_argument('--no-sandbox')
options.add_argument('start-maximized')
options.add_argument('--disable-infobars')
# options.add_argument('--disable-dev-shm-usage')
# options.add_argument('--disable-browser-side-navigation')
options.add_argument("--remote-debugging-port=9222")
options.add_argument('--disable-gpu')
# options.add_argument("--disable-logging")
options.add_argument("--log-level=3")
#options.headless = True
# to open 20 diff windows
for i in range(20):
driver = webdriver.Chrome()
#executable_path=r'C:\Users\rohit\AppData\Local\Programs\Python\Python39\Scripts\chromedriver.exe', options=options)
with open('file.txt') as k:
accs = k.readlines()
for line in accs:
unam, pwd, a, b,c,d,e,f,g,h,i,j,k,l = line.split(':')
print('Vera Started')
#driver = webdriver.Chrome(options=options)
print('Driver Loaded')
# unam = input('Username: ')
# pwd = input('Password: ')
scraper.login(driver, unam, pwd)
ask = input('Enter 1 to continue: ')
if ask == '1':
# a = input('Enter First Name: ')
# b = input('Enter Last Name: ')
# c = input('Enter Middle Name: ')
# d = input('Enter Suffix: ')
# e = input('Enter Occupation: ')
# f = input('Enter SSN: ')
# g = input('Enter DOB: ')
# h = input('Enter Steert Adress: ')
# i = input('Enter Apartmenet NO: ')
# j = input('Enter City: ')
# k = input('Enter State: ')
# l = input('Enter Zip: ')
scraper.taxpayer(driver, a, b, c, d, e, f, g, h, i, j, k, l)
我希望我是对的,我希望没有错误 另外,即使我设置了日志级别 3,它仍然显示错误 需要解决这个问题 谢谢 请很快回答我
I want to achieve to open 20+ or 10+ tabs at all the same time with one driver.. and if i use an for loop.. it just open but closes the exsiting and idk why i think i have commited some mistakes..
and i want to know the things..
1. Open Differnt Windows
2. Shouldnt Crash
3. Need to enter diff diff values
My Code :
def start():
options = webdriver.ChromeOptions()
options.add_argument(
"user-data-dir=C:\\Users\\rohit\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
options.add_experimental_option("useAutomationExtension", False)
options.add_experimental_option(
"excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--disable-blink-features=AutomationControlled")
# options.add_argument('--no-sandbox')
options.add_argument('start-maximized')
options.add_argument('--disable-infobars')
# options.add_argument('--disable-dev-shm-usage')
# options.add_argument('--disable-browser-side-navigation')
options.add_argument("--remote-debugging-port=9222")
options.add_argument('--disable-gpu')
# options.add_argument("--disable-logging")
options.add_argument("--log-level=3")
#options.headless = True
# to open 20 diff windows
for i in range(20):
driver = webdriver.Chrome()
#executable_path=r'C:\Users\rohit\AppData\Local\Programs\Python\Python39\Scripts\chromedriver.exe', options=options)
with open('file.txt') as k:
accs = k.readlines()
for line in accs:
unam, pwd, a, b,c,d,e,f,g,h,i,j,k,l = line.split(':')
print('Vera Started')
#driver = webdriver.Chrome(options=options)
print('Driver Loaded')
# unam = input('Username: ')
# pwd = input('Password: ')
scraper.login(driver, unam, pwd)
ask = input('Enter 1 to continue: ')
if ask == '1':
# a = input('Enter First Name: ')
# b = input('Enter Last Name: ')
# c = input('Enter Middle Name: ')
# d = input('Enter Suffix: ')
# e = input('Enter Occupation: ')
# f = input('Enter SSN: ')
# g = input('Enter DOB: ')
# h = input('Enter Steert Adress: ')
# i = input('Enter Apartmenet NO: ')
# j = input('Enter City: ')
# k = input('Enter State: ')
# l = input('Enter Zip: ')
scraper.taxpayer(driver, a, b, c, d, e, f, g, h, i, j, k, l)
I hope i am right and i wish there is no Error
Also Even though i have setup log level 3 it still shows error
need a fix for this
Thank you
Kindy answer me real quick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
多次使用
driver = webdriver.Chrome()
您会尝试打开许多浏览器,而不是选项卡。您必须将每个浏览器分配给单独的变量,因为当您再次分配给同一变量时,它会自动删除以前的浏览器。
除了使用列表之外,您还可以访问所有浏览器 -
all_drivers[0]
、all_drivers[1]
等。使用单个
driver
您只能访问最后打开的浏览器。顺便说一句:当我使用 Firefox() 运行时,即使我将新浏览器分配给同一个变量,它也会保持打开所有浏览器 - 但这样我就无法访问以前的浏览器。
如果您想打开选项卡,那么您可以执行
或使用 JavaScript
要在选项卡之间切换,您可以获取当前选项卡的处理程序
,然后使用它切换到此选项卡
。对于更多选项卡,您可以将它们保留在列表中。
您还应该可以使用列表
driver.window_handles
访问所有选项卡。文档: current_window_handle 和 window_handles
完整工作代码:
Using many times
driver = webdriver.Chrome()
you try to open many browsers, not tabs.You would have to assign every browser to separated variable because when you assign again to the same variable then it automatically removes previous browser.
Besides using list you have access to all browsers -
all_drivers[0]
,all_drivers[1]
, etc.Using single
driver
you could access only last open browser.BTW: when I run with
Firefox()
then it keeps open all browsers even if I assign new browser to the same variable - but this way I can't access previous browsers.And if you want to open tabs then you may do
or use JavaScript
To switch between tabs you can get handler to current tab
and later use it to switch to this tab
For more tabs you could keep them on list.
You should have also access to all tabs using list
driver.window_handles
.Doc: current_window_handle and window_handles
Full working code: