Reputation: 67
I'm working on a Python script to open multiple web pages at once, and then search. Python will open them one by one but it's painfully slow. I have 12 tabs that open inside of Chrome. Here's the code I'm using to open a website in a new tab for each website inside of Chrome. Any suggestions? (Using 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')
Upvotes: 2
Views: 7865
Reputation: 43
Now, one can simply do (with the default browser):
import webbrowser
url1 = "www.google.com"
url2 = "www.facebook.com"
webbrowser.open_new(url1)
webbrowser.open_new(url2)
Upvotes: 0
Reputation: 116
I'm new to this, but I hope this helps your problem. This will open a window and then open tabs within that window.
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)
How to have it open up a new browser since I can't get open_new()
to work.
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')
Upvotes: 5
Reputation: 67
What I ended up doing was opening one web page using- driver.get('https://www.website1.com')
then emulating key strokes to open a new tab in chrome, type the web address and hit enter. That seemed to be the fastest way to get the pages to load and not have to wait for them to load one and then move on to the next one.
Upvotes: 1