Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to get HTTP STATUS CODE == 200 when loading a page using Selenium? #3941

Answered by mdmintz
heavenyoung1 asked this question in Q&A
Discussion options

Before interacting with the page using SELENIUM, I want to make sure that the page request HTTP STATUS CODE == 200. Is this possible, and if so, how?

You must be logged in to vote

As Google says, you would use the requests library to get the response code before using Selenium on the page:

>>> import requests
>>> response = requests.head("https://example.com")
>>> response.status_code
200

Replies: 1 comment 6 replies

Comment options

As Google says, you would use the requests library to get the response code before using Selenium on the page:

Screenshot 2025年08月23日 at 9 50 55 AM
>>> import requests
>>> response = requests.head("https://example.com")
>>> response.status_code
200
You must be logged in to vote
6 replies
Comment options

You should have specified that in your original question. With SeleniumBase, you can search the page for something that only appears when you get a 200 (or for something that appears when you don't get a 200). Rather than looking directly for the response code, look for something that appears in the HTML of the web page.

Comment options

In my question, I wrote that I want to use Selenium for the request. I assumed that there was some function that returned the HTTP response code. I understand you now; there is no such function.

Comment options

My difficulty lies in the fact that I use Selenium specifically because it is capable of bypassing anti-bot blocking. When using the request library, I don't get a 200 code, but I assumed that Selenium had similar functionality, like requests.get. Heh, maybe I need something like that? Probably that would be convenient, don't you think?

Comment options

As mentioned earlier, the Status Code is not something returned with the page load. You get the HTML.
You may be able to determine the Status Code with that by looking for something that's in the HTML.

Comment options

Yes, I understand. I'm saying that it would probably be good if there was a similar function for returning the HTTP status code. I understand that this is not implemented, and I also understand that this can be obtained from the page itself. Thank you again.

Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /