how to request if href have only https in selenium python

117 Views Asked by At

I'm try to finding broken links from website using selenium python. I almost done the script and executed its working good. but I'm facing issue while request the link to get status code. In my website anchor attribute have href="javascript:void(0) So I try to get href attribute value and request to get status-code(response code) but this javascript:void(0) is not a link. How Can i solve this?

anchor = driver.find_elements_by_tag_name("a")

for anchors in anchor:
if(requests.head(anchors.get_attribute('href')).status_code):
    print(anchors.get_attribute('href'), "Valid link")
else:
    print(anchors.get_attribute('href'), "Broken link")
1

There are 1 best solutions below

1
Conrad Albrecht On

javascript:void(0) is just a dummy placeholder. Your website may have JavaScript which actually handles clicks on that link. You'll have to investigate your website to see what it's actually designed to do on those clicks.