“Selenium Screenshot Python User Agent” Code-Antworten

Selenium Screenshot Python User Agent

#I want each time chrome opens it will automatically run with a useragent taken from the txt file in order from line 1 -> line 10 . I'm a new member, someone please help me

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

key="something"
while key != "q":    
 username_list = list()
 with open("a.txt") as file:
     for line in file:
        agent = line.split(':')
        username_list.append((agent))  
 options = Options()
 options.add_argument(f'user-agent={agent[0]}')
 driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Program 
Files (x86)\chromedriver.exe')
 driver.get("https://www.deviceinfo.me/")
 time.sleep(5) # Let the user actually see something!
 driver.quit()
key=str(input())
Determined Dog

Selenium Screenshot Python User Agent

from selenium import webdriver

user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36'

options = webdriver.ChromeOptions()
# specify headless mode
options.add_argument('headless')
# specify the desired user agent
options.add_argument(f'user-agent={user_agent}')
driver = webdriver.Chrome(chrome_options=options)

# user-agent is now set
Magnificent Mole

Ähnliche Antworten wie “Selenium Screenshot Python User Agent”

Fragen ähnlich wie “Selenium Screenshot Python User Agent”

Weitere verwandte Antworten zu “Selenium Screenshot Python User Agent” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen