-
Notifications
You must be signed in to change notification settings - Fork 1.4k
How to get HTTP STATUS CODE == 200 when loading a page using Selenium? #3941
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
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.
Beta Was this translation helpful? Give feedback.