简体   繁体   English

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

[英]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.我正在尝试使用 selenium webdriver 获取页面的 url 的 HTTP 响应。 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根据我的经验,我建议像这样使用Browsermob

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

暂无
暂无

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

相关问题 如何通过使用 driver.find_elements(By.XPATH,'') 和 Python Selenium 来获取汽车名称 - How can i get car names by using driver.find_elements(By.XPATH,'') with Python Selenium 我如何使用 Python 中的 Selenium 驱动程序在 Facebook 上发送消息 - How I can send a message on Facebook using Selenium Driver in Python 如何使用Python硒Web驱动程序chorme从XHR中的网络调用获取响应json数据 - how to get the response json data from network call in XHR using Python selenium web driver chorme 在 driver.get() 方法中使用 Selenium web 驱动程序我无法通过某些 http 身份验证凭据 - Using Selenium web driver i cant pass certain http authenitication credentials in the driver.get() method 如何从 Selenium webdriver Firefox 中的 `driver.page_source` 获取 HTTP 请求的原始 JSON 响应 - How to get the raw JSON response of a HTTP request from `driver.page_source` in Selenium webdriver Firefox Python / Selenium:如何使用无头Chrome驱动程序模拟uBlock或AdBlock等扩展程序? - Python/Selenium: How can I emulate extensions such as uBlock or AdBlock using a headless Chrome driver? 如何使用Selenium chrome驱动程序按名称过滤网络呼叫条目? - How can I filter entries of network calls by name in Python using selenium chrome driver? 如何使用python在selenium chrome web驱动程序中使用身份验证设置代理 - How can i set proxy with authentication in selenium chrome web driver using python 如何使用 Selenium(-Wire) 获取 HTTP 响应代码 - How to get HTTP Response Code using Selenium(-Wire) 如何使用 Python 将选项传递给 Selenium Chrome 驱动程序? - How do I pass options to the Selenium Chrome driver using Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM