파이썬, 셀레니움 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
'웹 크롤링, 스크래핑' 카테고리의 다른 글
파이썬, 셀레니움 '텍스트'로 요소 찾기 (0) | 2022.07.17 |
---|---|
파이썬, 셀레니움 스크롤 예제 (0) | 2022.07.17 |
파이썬, 셀레니움 shadow dom 처리 예제(크롬 사용 기록 삭제) (0) | 2022.07.17 |
파이썬, 셀레니움 예외 처리 (0) | 2022.07.17 |
파이썬, 셀레니움 연속 작업 Actions 예제 (0) | 2022.07.16 |