简体   繁体   中英

How can i get http response using Selenium driver with PYTHON?

I am trying to get url's HTTP response of a page using selenium webdriver. Can anyone please help me with that.

I am trying to do with some code i found elsewhere

from selenium import webdriver
import logging

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

# enable browser logging
d = DesiredCapabilities.CHROME
d['loggingPrefs'] = {'performance': 'ALL'}

driver = webdriver.Chrome(executable_path="C:\\Users\\Admin\\PythonFiles\\chromedriver.exe",
                          service_args=["--verbose", "--log-path=D:\\selenium.log"],
                          desired_capabilities=d)

driver.get('https://www.atg.party')

print(driver.title)

print(driver.page_source)

performance_log = driver.get_log('performance')
print(str(performance_log).strip('[]'))

for entry in driver.get_log('performance'):
    print(entry)}

it is showing an error:

raise exception_class(message, screen, stacktrace)

    selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: log type 'performance' not found
      (Session info: chrome=77.0.3865.120)

I had the same problem and I wanted to get the log with this method but after that, my log was not a complete network log. Based on my experience, I suggest using Browsermob like this

With using this method you can have a Har file which is a JSON-formatted archive file that has logs of a web browser's interaction with a site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM