简体   繁体   English

您能否让我知道在 selenium python 的浏览器中的网络选项卡中捕获除 200 以外的状态代码的代码吗?

[英]Can you please let me know the code to capture the status codes other than 200 in network tab in browser in selenium python?

My application has multiple pages and i want to write a code to capture the status other than 200 in the network tab of the browser.我的应用程序有多个页面,我想编写一个代码来捕获浏览器的网络选项卡中除 200 之外的状态。 I want to do this using Selenium and Python我想使用 Selenium 和 Python 来做到这一点

It will be helpful if you can share this如果你能分享这个会很有帮助

selenium 4: selenium 4:

from time import sleep
from selenium import webdriver

import json

options = webdriver.ChromeOptions()

options.set_capability("goog:loggingPrefs", {  # old: loggingPrefs
    "performance": "ALL"})

driver = webdriver.Chrome(
    options=options
)

driver.get("https://www.google.com")
sleep(5)

# returns a list of all events
logs = driver.get_log("performance")


#iterate through the list
for log in logs:
    #converting the string to dict
    a= json.loads(log['message'])

    #get the resolved requests and get the response content from it
    if "Network.responseReceived" == a['message']["method"]:
        print(a["message"]["params"]["response"]["url"])
        print(a["message"]["params"]["response"]["status"])

        #you can see the full request object in the demofile2.txt created in your current directory
        f = open("demofile2.txt", "a")
        f.write(json.dumps(a, indent=4, sort_keys=True))

selenium 3 selenium 3

from time import sleep
from selenium import webdriver

import json

caps = DesiredCapabilities.CHROME
#as per latest docs
caps['goog:loggingPrefs'] = {'performance': 'ALL'}
driver = webdriver.Chrome(desired_capabilities=caps)

driver.get("https://www.google.com")
sleep(5)

# returns a list of all events
logs = driver.get_log("performance")


#iterate through the list
for log in logs:
    #converting the string to dict
    a= json.loads(log['message'])

    #get the resolved requests and get the response content from it
    if "Network.responseReceived" == a['message']["method"]:
        print(a["message"]["params"]["response"]["url"])
        print(a["message"]["params"]["response"]["status"])

        #you can see the full request object in the demofile2.txt created in your current directory
        f = open("demofile2.txt", "a")
        f.write(json.dumps(a, indent=4, sort_keys=True))

you can log PERFORMANCE log and then get the Network.receivedresponse events您可以记录 PERFORMANCE 日志,然后获取 Network.receivedresponse 事件

暂无
暂无

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

相关问题 请在以下python代码中让我知道问题 - Please let me know the problem in the following python code 谁能告诉我这条线在我的 python 代码中做了什么: - can anyone please let me know what does this line do in my python CODE: 您能否让我知道如何使用python-social-auth的PIPELINE更改默认数据库字段? - Would you please let me know how to change default database field with PIPELINE of python-social-auth? (python)你能告诉我下面代码中有什么问题吗 - (python) Can you please tell me what is the problem in the code below 你能让我知道 Python 中的 rep() function 吗? - Could you let me know about rep() function in Python? 我对镶木地板文件和 python 完全陌生,谁能告诉我如何读取 pyspark 中带有标题的镶木地板文件 - I am completely new to parquet files and python, Can anyone please let me know how to read parquet file with headers in pyspark 有人可以扫描我编写的这段 Python 代码并让我知道我做错了什么吗? - Can someone scan over this Python code that I wrote and let me know what I did wrong? 如何添加过滤器以便我可以对向经理报告的员工分组? 请指导我。 也让我知道下面的代码是否正确 - How to add filters so that I can group employees reporting to manager ?? Please guide me. Also let me know if the below code is correct or not IndexError : list index out of range 请让我知道为什么我的代码不起作用 - IndexError : list index out of range Please let me know why isnt my code working 有人可以向我解释这段代码 - python 3 - can someone please explain to me this code - python 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM