繁体   English   中英

如何使用 Selenium 驱动程序和 PYTHON 获得 http 响应?

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

我正在尝试使用 selenium webdriver 获取页面的 url 的 HTTP 响应。 谁能帮我解决这个问题。

我正在尝试处理我在其他地方找到的一些代码

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)}

它显示错误:

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)

我遇到了同样的问题,我想用这种方法获取日志,但是在那之后,我的日志不是完整的网络日志。 根据我的经验,我建议像这样使用Browsermob

通过使用这种方法,您可以获得一个Har文件,它是一个 JSON 格式的存档文件,其中包含 web 浏览器与站点交互的日志。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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