gpt4 book ai didi

python-3.x - 如何在 Selenium + Python 中的新选项卡上打开网址列表?

转载 作者:行者123 更新时间:2023-12-02 20:32:27 24 4
gpt4 key购买 nike

代码片段:

import selenium
from selenium import webdriver

driver = webdriver.Chrome()
urls =['fb.com','instgram.com' , 'youtube.com']
for url in urls:
driver.get(url)
driver.close()

问题是它在前一个链接之上打开新链接。我希望每个网站都在新选项卡上打开。

最佳答案

打开第一个 URL,然后使用 target: _blank 在新选项卡中打开每个 URL:

driver.get(urls[0])
for url in urls[1:]:
driver.execute_script('window.open("{}", "_blank");'.format(url))

瞧,您应该拥有三个带有三个不同 URL 的选项卡。

请注意您的网址:这些网址无效。确保它们前面都有 httphttps。而且您不小心写成了 instgram 而不是 instagram。 :P

关于python-3.x - 如何在 Selenium + Python 中的新选项卡上打开网址列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48270354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com