Skip to content

Instantly share code, notes, and snippets.

@pakoy3k
Created March 9, 2020 18:47
Show Gist options
  • Save pakoy3k/4e425306d85a6fb57d0173f03dc11035 to your computer and use it in GitHub Desktop.
Save pakoy3k/4e425306d85a6fb57d0173f03dc11035 to your computer and use it in GitHub Desktop.
Seleniun test with chrome, count all links "href" and validate the status
#pip install selenium
#pip install requests
#pip install chromedriver
# dev -> @pakoy3k
from selenium import webdriver
import time
import requests
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(chrome_options=options)
driver.get("http://gortsolutions.com")
time.sleep(5)
Links = driver.find_elements_by_css_selector("a")
i = 0
for link in Links:
web = link.get_attribute('href')
if web is not None:
if "http" in web:
print(i)
i = i + 1
r = requests.head(link.get_attribute('href'))
print(link.get_attribute('href'), r.status_code)
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment