I have a code that returns the title of a list of URLs. Since I have to wait for a loaded URL to update before the title is returned, I'm wondering if there's a way to load more than one URL at a time and return both titles at once.
This is the code:
from pyvirtualdisplay import Display
from time import sleep
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.firefox.options import Options
display = Display(visible=0, size(800,600))
display.start()
urlsFile = open ("urls.txt", "r")
urls = urlsFile.readLines()
driver = webdriver.Firefox(executable_path='/usr/local/lib/geckodriver/geckodriver')
driver.set_page_load_timeout(60)
for url in urls:
try:
driver.get(url)
sleep(0.8)
print(driver.title)
except TimeoutException as e:
print("Timeout")
If I try to do this:
driver = webdriver.Firefox(executable_path='/usr/local/lib/geckodriver/geckodriver')
driver2 = webdriver.Firefox(executable_path='/usr/local/lib/geckodriver/geckodriver')
for url in urls:
try:
driver.get(url)
driver2.get(url)
sleep(0.8)
print(driver.title)
print(driver2.title)
except TimeoutException as e:
print("Timeout")
The URL that driver2 gets is the same one that driver1 gets. Is it possible to have driver2 get the URL next in line, to load both of them like that without losing time?