How to get status code by using selenium.py (python code)

前端 未结 12 1116
深忆病人
深忆病人 2020-11-30 01:01

I am writing a selenium script by python, but I think I don\'t see any information about:

How to get http status code from selenium Python code.

12条回答
  •  我在风中等你
    2020-11-30 01:53

    I've been surfing the net for about 3 hours and I found not a single way to do that with web-driver. I'v not ever worked with selenium directly. The only suggestion that came in my mind is to use module "requests" like this:

    import requests
    from selenium import webdriver
    
    driver = webdriver.get("url")
    r = requests.get("url")
    print r.status_code
    

    Complete tutorial about using requests is here and you can install the module using the command pip install requests.

    But there is a problem that may not always happen, but you should focus that driver's response and request's response are not the same; so you just get the request's status code and if the url responses are not stable it probably causes wrong results.

提交回复
热议问题