1234567891011121314151617181920212223242526272829303132333435363738394041 |
- UAFILE = "useragent"
- from selenium import webdriver
- options = webdriver.ChromeOptions()
- options.add_argument("--no-sandbox")
- options.add_argument("--disable-gpu")
- options.add_argument("--disable-dev-shm-usage")
- options.add_argument("window-size=1280x1024")
- options.add_argument("--headless=new")
- driver = webdriver.Remote(command_executor="http://127.0.0.1:9515", options=options)
- ua = driver.execute_script("return navigator.userAgent;")
- driver.quit()
- print(f"Selenium Google UserAgent={ua}")
- ua = ua.replace("HeadlessChrome", "Chrome")
- with open(UAFILE, "wt") as fp:
- print(f"{ua}", file=fp)
- with open("useragent.py", "wt") as fp:
- print(f'USERAGENT = "{ua}"', file=fp)
|