파이썬, 셀레니움 XHR 데이터 확인 예제
파이썬, 셀레니움 XHR 데이터 확인 예제
from selenium.webdriver import DesiredCapabilities
import json
capabilities = DesiredCapabilities.CHROME
capabilities["goog:loggingPrefs"] = {"performance": "ALL"} # newer: goog:loggingPrefs
try:
s = Service(f'./{chrome_ver}/chromedriver.exe')
driver = webdriver.Chrome(service=s, options=option, desired_capabilities=capabilities)
except:
chromedriver_autoinstaller.install(True)
s = Service(f'./{chrome_ver}/chromedriver.exe')
driver = webdriver.Chrome(service=s, options=option, desired_capabilities=capabilities)
driver.implicitly_wait(10)
driver.get('blablablabla~~~')
logs_raw = driver.get_log("performance")
logs = [json.loads(lr["message"])["message"] for lr in logs_raw]
def log_filter(log_):
# is an actual response and json
return ( log_["method"] == "Network.responseReceived" and
"json" in log_["params"]["response"]["mimeType"] )
for log in filter(log_filter, logs):
request_id = log["params"]["requestId"]
resp_url = log["params"]["response"]["url"]
print(f"Caught {resp_url}")
print(driver.execute_cdp_cmd("Network.getResponseBody", {"requestId": request_id}))
[참고] XHR (XML Http Request) 이란
https://iotengineer.tistory.com/3
XHR (XML Http Request) 이란
해당 포스트는 web scraping(web crawling)을 위한 기능 중 하나인 XHR에 관한 포스트입니다. XMLHttpRequest(XHR) 객체는 서버와 상호작용하기 위하여 사용됩니다. 전체 페이지의 새로고침없이도 URL 로부터
iotengineer.tistory.com