selenium webdriver python with open(“sites.txt”)

How to open a list of URLs on new tabs, in Selenium + Python! I want each site to open on a new windows from the list of URL in a txt file like (sites.txt). here is how I have setup.

import time
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
import fileinput
import urllib3
import sys

count = 0
while (1):
        with open("sites.txt") as f:
            for line_terminated in f:
                count = count + 0 
            line = line_terminated.rstrip('\n')
        print ()," ", count
        service = Service(r'geckodriver.exe')
        options = webdriver.FirefoxOptions()
        driver = webdriver.Firefox(service=service, options=options)
        try:
                driver.get(line)
                time.sleep(5)
                driver.quit()
        except:
                driver.quit()
                print(), "Error ", line
  • #i have tried the script above and result is only reading the last URL from list:

Read more here: Source link