How to find all broken/invalid links from a webpage using python selenium?

0 votes
How to find all broken/invalid links from a webpage using python selenium?
Jul 30 in Selenium by Ruchi
173 views

1 answer to this question.

0 votes

Hi Ruchi, following lines of code can help you in finding qall broken/invalid links on a webpage using python selenium webdriver:

webdriver.get(PAGEURL)

links = webdriver.find_elements_by_css_selector("a")

for link in links:

  if (requests.head(link.get_attribute('href')).status_code == 200):
  print("Valid link")
  else:
  print("Broken link")
answered Jul 31 by Anvi
• 13,520 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to Hover using Mouse in python using Webdriver

from selenium.webdriver.common.action_chains import ActionChains def hover(self): ...READ MORE

answered Aug 8, 2018 in Selenium by Meci Matt
• 9,420 points
492 views
0 votes
1 answer

How to launch browsers using Python-Selenium?

Hey Nikita, to launch browser in Python-Selenium, ...READ MORE

answered May 24 in Selenium by Anvi
• 13,520 points
34 views
0 votes
1 answer
0 votes
1 answer