Created
February 12, 2020 14:51
-
-
Save atucom/68cfe8499eec0c5779fdb8b34c3c7e37 to your computer and use it in GitHub Desktop.
Better Link Grabber
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from selenium import webdriver | |
import argparse | |
import re | |
from time import sleep | |
def get_links(url): | |
options = webdriver.ChromeOptions() | |
options.add_argument('--ignore-certificate-errors') | |
options.add_argument('--headless') | |
options.add_argument('--user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36"') | |
driver = webdriver.Chrome(options=options) | |
driver.get(url) | |
sleep(3) | |
#return a tags once page is rendered and javascript executed | |
a_tags = driver.execute_script('return document.getElementsByTagName("a")') | |
for tag in a_tags: | |
print(tag.get_attribute('href')) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument("url" ,help='Target URL to scrape') | |
args = parser.parse_args() | |
#handle arguments | |
if args.url: | |
get_links(args.url) | |
else: | |
exit(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment