Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimization for getting status of url(using threads) #27

Merged
merged 1 commit into from
Jul 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added modules/__init__.pyc
Binary file not shown.
Binary file added modules/bcolors.pyc
Binary file not shown.
Binary file added modules/getemails.pyc
Binary file not shown.
40 changes: 25 additions & 15 deletions modules/getweblinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,35 @@
import urllib.request
from modules.bcolors import bcolors
import bs4
import time
import threading
import http

def link_status(web):
link_live = False
try:
urllib.request.urlopen(web)
link_live = True
print(web)
except urllib.error.HTTPError as e:
print(bcolors.On_Red+web+bcolors.ENDC)
except urllib.error.URLError as e:
print(bcolors.On_Red+web+bcolors.ENDC)
except http.client.RemoteDisconnected as e:
print(bcolors.On_Red+web+bcolors.ENDC)
return


"""Get all onion links from the website"""
def getLinks(soup,ext,live=0):
_soup_instance = bs4.BeautifulSoup
extensions = []
if ext:
for e in ext:
extensions.append(e)
extensions.append(e)
if isinstance(type(soup), type(_soup_instance)):
websites = []
start_time = time.time()
for link in soup.find_all('a'):
web_link = link.get('href')
if web_link != None:
Expand All @@ -31,23 +50,14 @@ def getLinks(soup,ext,live=0):
print (bcolors.OKGREEN+'Websites Found - '+bcolors.ENDC+str(len(websites)))
print ('-------------------------------')
if live:
threads = []
for web in websites:
flag=1
try:
urllib.request.urlopen(web)
except urllib.error.HTTPError as e:
if e.code:
print(bcolors.On_Red+web+bcolors.ENDC)
flag=0
except urllib.error.URLError as e:
print(bcolors.On_Red+web+bcolors.ENDC)
flag=0

if flag:
print(web)
t = threading.Thread(target=link_status, args=(web,))
threads.append(t)
t.start()
else:
for web in websites:
print(web)
print(web)
return websites
else:
raise('Method parameter is not of instance bs4.BeautifulSoup')