seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.46k stars 910 forks source link

How can I get data from SeleniumBase network logs? #2650

Closed TranTienVan closed 3 months ago

TranTienVan commented 3 months ago

I'm trying to use the selenium function driver.get_log() in seleniumbase, but it doesn't seem to work. Can you help? Thank you!

mdmintz commented 3 months ago

Network log capture must be enabled to take effect (log_cdp=True):

See the example: SeleniumBase/examples/raw_cdp_logging.py

from rich.pretty import pprint
from seleniumbase import Driver

driver = Driver(uc=True, log_cdp=True)
try:
    driver.uc_open_with_reconnect("https://seleniumbase.io/apps/turnstile")
    driver.switch_to_frame("iframe")
    driver.uc_click("span.mark")
    driver.sleep(3)
    pprint(driver.get_log("performance"))
finally:
    driver.quit()

For more ways to get network logs in SeleniumBase, see: https://stackoverflow.com/a/76557752/7058266