diff --git a/modules/getemails.py b/modules/getemails.py index e81715b3..bd9f84ca 100644 --- a/modules/getemails.py +++ b/modules/getemails.py @@ -22,7 +22,7 @@ def getMails(soup): emails = get_urls_from_page(soup, email=True) - """Pretty print output as below""" + # Pretty print output as below print('') print(b_colors.OKGREEN+'Mails Found - '+b_colors.ENDC+str(len(emails))) print('-------------------------------') diff --git a/modules/getweblinks.py b/modules/getweblinks.py index 7108663c..79b7883d 100644 --- a/modules/getweblinks.py +++ b/modules/getweblinks.py @@ -28,7 +28,7 @@ def get_links(soup, ext=False, live=False): b_colors = Bcolors() if isinstance(soup, BeautifulSoup): websites = get_urls_from_page(soup, extension=ext) - """Pretty print output as below""" + # Pretty print output as below print(''.join((b_colors.OKGREEN, 'Websites Found - ', b_colors.ENDC, str(len(websites))))) print('------------------------------------') diff --git a/modules/net_utils.py b/modules/net_utils.py index bd2f1b16..be71d46d 100644 --- a/modules/net_utils.py +++ b/modules/net_utils.py @@ -1,11 +1,8 @@ import re import requests -from requests.exceptions import ConnectionError, HTTPError - def check_connection(url): - print("Attempting to connect to {site}".format(site=url)) if get_url_status(url) != 0: return 1 @@ -28,12 +25,12 @@ def get_url_status(url, headers=False): """ try: if headers: - resp = requests.get(url, headers=headers) + resp = requests.get(url, headers=headers) else: - resp = requests.get(url) + resp = requests.get(url) resp.raise_for_status() return resp - except (ConnectionError, HTTPError): + except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError): return 0 @@ -41,7 +38,7 @@ def is_url(url): pattern = r"^https?:\/\/(www\.)?([a-z,A-Z,0-9]*)\.([a-z, A-Z]+)(.*)" regex = re.compile(pattern) if regex.match(url): - return 1 + return 1 return 0 diff --git a/modules/pagereader.py b/modules/pagereader.py index 6598be99..bf49d4ce 100644 --- a/modules/pagereader.py +++ b/modules/pagereader.py @@ -1,7 +1,7 @@ +import sys from bs4 import BeautifulSoup from modules.net_utils import get_url_status from modules.bcolors import Bcolors -from sys import exit def connection_msg(site): @@ -24,23 +24,23 @@ def read_first_page(site): continue if attempts_left == 2: - https_url = 'https://'+site + https_url = 'https://' + site print(next(connection_msg(https_url))) response = get_url_status(https_url, headers) if response != 0: - page = BeautifulSoup(response.text, 'html.parser') - return page, response + page = BeautifulSoup(response.text, 'html.parser') + return page, response else: attempts_left -= 1 continue if attempts_left == 1: - http_url = 'http://'+site + http_url = 'http://' + site print(next(connection_msg(http_url))) response = get_url_status(http_url, headers) if response != 0: - page = BeautifulSoup(response.text, 'html.parser') - return page, response + page = BeautifulSoup(response.text, 'html.parser') + return page, response else: attempts_left -= 1 continue @@ -48,7 +48,8 @@ def read_first_page(site): if not attempts_left: msg = ''.join(("There has been an {err} while attempting to ", "connect to {site}.")).format(err=err, site=site) - exit(msg) + sys.exit(msg) + def get_ip(): """Returns users tor ip address diff --git a/torBot.py b/torBot.py index 655ac312..feebe36a 100644 --- a/torBot.py +++ b/torBot.py @@ -151,7 +151,7 @@ def get_args(): return parser.parse_args() -def main(conn=False): +def main(): args = get_args() connect(args.ip, args.port) link = args.url @@ -199,7 +199,7 @@ def main(conn=False): if __name__ == '__main__': try: - main(conn=True) + main() except KeyboardInterrupt: print("Interrupt received! Exiting cleanly...")