728x90
from selenium import webdriver
from selenium.webdriver.common.by import By
# Headless Chrome(Chrome without Chrome) background에서 Chrome을 실행하기
options = webdriver.ChromeOptions()
options.headless = True
options.add_argument('window-size=1920x1080')
options.add_argument('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/x.0.0.0 Safari/537.36')
browser = webdriver.Chrome(options=options)
browser.maximize_window()
url = 'https://www.whatismybrowser.com/detect/what-is-my-user-agent/'
browser.get(url)
detected_value = browser.find_element(By.ID, 'detected_value')
print(detected_value.text)
browser.quit()
########################################################
# 1. line 8 없이 실행하면 user-agent 값이 .../HeadlessChrome/... 으로 return
# Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/x.x.x.x Safari/537.36
# 2. user-agent 값을 argument로 지정할 경우
# Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/x.0.0.0 Safari/537.36
728x90
'Selenium' 카테고리의 다른 글
[bs4/selenium] 페이지 정보 가져오기 (0) | 2022.07.25 |
---|---|
[selenium] return document.body.scrollHeight이 0일때 (0) | 2022.07.24 |