from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent
options = Options()
ua = UserAgent()
userAgent = ua.random
print(userAgent)
options.add_argument(f'user-agent={userAgent}')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\ChromeDriver\chromedriver_win32\chromedriver.exe')
driver.get("https://www.google.co.in")
driver.quit()
Result of 3 consecutive execution is as follows :
#First Execution :
Mozilla/5.0 (Windows NT 4.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36
#Second Execution :
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.517 Safari/537.36
#Third Execution :
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17
출처: https://stackoverflow.com/questions/49565042/way-to-change-google-chrome-user-agent-in-selenium
'Python > Web crowling' 카테고리의 다른 글
열려있는 chrome에서 크롤링 (4) | 2020.02.09 |
---|---|
selenium에서 자식 창, 부모 창 이동하기 (0) | 2020.02.09 |
selenium으로 크롤링 시 현재 실행중인 크롬에서 실행하기 (0) | 2020.02.09 |
웹 크롤러 - 봇 탐지 우회하기 (1) | 2020.02.09 |
창없는 크롬으로 크롤링하기 (0) | 2020.02.09 |