【发布时间】:2019-02-03 12:50:28
【问题描述】:
我正在编写一个 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')
【问题讨论】:
-
你可以使用pytest对每个网页进行测试,然后使用xdist插件在线程中运行测试。
标签: python python-3.x automation selenium-chromedriver