📜  selenium screenshot python用户代理 - Python代码示例

📅  最后修改于: 2022-03-11 14:45:17.369000             🧑  作者: Mango

代码示例2
#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())