Skip to content

Commit 857f860

Browse files
committed
Ignore certificate errors by default in get_link_status_code()
1 parent a5cef6c commit 857f860

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4561,10 +4561,17 @@ def get_unique_links(self):
45614561
links = page_utils._get_unique_links(page_url, soup)
45624562
return links
45634563

4564-
def get_link_status_code(self, link, allow_redirects=False, timeout=5):
4564+
def get_link_status_code(
4565+
self,
4566+
link,
4567+
allow_redirects=False,
4568+
timeout=5,
4569+
verify=False,
4570+
):
45654571
"""Get the status code of a link.
45664572
If the timeout is set to less than 1, it becomes 1.
45674573
If the timeout is exceeded by requests.get(), it will return a 404.
4574+
If "verify" is False, will ignore certificate errors.
45684575
For a list of available status codes, see:
45694576
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
45704577
"""
@@ -4573,7 +4580,10 @@ def get_link_status_code(self, link, allow_redirects=False, timeout=5):
45734580
if timeout < 1:
45744581
timeout = 1
45754582
status_code = page_utils._get_link_status_code(
4576-
link, allow_redirects=allow_redirects, timeout=timeout
4583+
link,
4584+
allow_redirects=allow_redirects,
4585+
timeout=timeout,
4586+
verify=verify,
45774587
)
45784588
return status_code
45794589

seleniumbase/fixtures/page_utils.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,31 @@ def _get_unique_links(page_url, soup):
209209
pass
210210
unique_links.append(link)
211211

212-
return unique_links
213-
214-
215-
def _get_link_status_code(link, allow_redirects=False, timeout=5):
212+
links = unique_links
213+
links = list(set(links)) # Make sure all duplicates were removed
214+
links = sorted(links) # Sort all the links alphabetically
215+
return links
216+
217+
218+
def _get_link_status_code(
219+
link,
220+
allow_redirects=False,
221+
timeout=5,
222+
verify=False,
223+
):
216224
"""Get the status code of a link.
217225
If the timeout is exceeded, will return a 404.
226+
If "verify" is False, will ignore certificate errors.
218227
For a list of available status codes, see:
219228
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
220229
"""
221230
status_code = None
222231
try:
223232
response = requests.get(
224-
link, allow_redirects=allow_redirects, timeout=timeout
233+
link,
234+
allow_redirects=allow_redirects,
235+
timeout=timeout,
236+
verify=verify,
225237
)
226238
status_code = response.status_code
227239
except Exception:

0 commit comments

Comments
 (0)