diff --git a/.travis.yml b/.travis.yml index 53853297..aa820c61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,3 +11,4 @@ install: - pip3 install bs4 script: - python3 test_getemails.py + - python3 test_getweblinks.py diff --git a/modules/__pycache__/getemails.cpython-35.pyc b/modules/__pycache__/getemails.cpython-35.pyc index d07f35bb..7ed24256 100644 Binary files a/modules/__pycache__/getemails.cpython-35.pyc and b/modules/__pycache__/getemails.cpython-35.pyc differ diff --git a/modules/__pycache__/getweblinks.cpython-35.pyc b/modules/__pycache__/getweblinks.cpython-35.pyc index e70d7b13..36599bc7 100644 Binary files a/modules/__pycache__/getweblinks.cpython-35.pyc and b/modules/__pycache__/getweblinks.cpython-35.pyc differ diff --git a/modules/getemails.py b/modules/getemails.py index 3eb4a3c8..232d0504 100644 --- a/modules/getemails.py +++ b/modules/getemails.py @@ -1,4 +1,3 @@ -#from bs4 import BeautifulSoup import bs4 """Get all emails from the website""" diff --git a/modules/getweblinks.py b/modules/getweblinks.py index de16a261..0a907c1b 100644 --- a/modules/getweblinks.py +++ b/modules/getweblinks.py @@ -1,17 +1,24 @@ +import bs4 + + """Get all onion links from the website""" def getLinks(soup): - websites = [] - for link in soup.find_all('a'): - email_link = link.get('href') - if email_link != None: - if 'http' in email_link: - websites.append(email_link) - else: - pass - """Pretty print output as below""" - print ('') - print ('Websites Found - '+str(len(websites))) - print ('-------------------------------') - for web in websites: - print (web) - return '' \ No newline at end of file + _soup_instance = bs4.BeautifulSoup + if isinstance(type(soup), type(_soup_instance)): + websites = [] + for link in soup.find_all('a'): + email_link = link.get('href') + if email_link != None: + if 'http' in email_link: + websites.append(email_link) + else: + pass + """Pretty print output as below""" + print ('') + print ('Websites Found - '+str(len(websites))) + print ('-------------------------------') + for web in websites: + print (web) + return '' + else: + raise('Method parameter is not of instance bs4.BeautifulSoup') diff --git a/tests/test_getemails.py b/tests/test_getemails.py index 8b575b08..019427ae 100644 --- a/tests/test_getemails.py +++ b/tests/test_getemails.py @@ -13,13 +13,11 @@ class getMailsTestCase(unittest.TestCase): def setUp(self): self.held, sys.stdout = sys.stdout, StringIO() - def test_return_emails_list(self): + def test_print_emails(self): data = "\nMails Found - 1\n-------------------------------\nadvertise@provaz.eu\n" getemails.getMails(soup) self.assertEqual(sys.stdout.getvalue(),data) - def tearDown(self): - sys.stdout.flush() if __name__ == '__main__': unittest.main() diff --git a/tests/test_getweblinks.py b/tests/test_getweblinks.py new file mode 100644 index 00000000..da133b23 --- /dev/null +++ b/tests/test_getweblinks.py @@ -0,0 +1,24 @@ +import sys +import os +import unittest +from io import StringIO +sys.path.append(os.path.abspath('../modules')) +import getweblinks +import pagereader + +soup = pagereader.readPage('http://www.whatsmyip.net/') + +class getLinksTestCase(unittest.TestCase): + + def setUp(self): + self.held, sys.stdout = sys.stdout, StringIO() + + def test_print_links(self): + data = "\nWebsites Found - 7\n-------------------------------\nhttp://ads.wsrs.net/www/delivery/ck.php?n=MyIP856a6b4\nhttp://ads.wsrs.net/www/delivery/ck.php?n=MyIPbf5d683\nhttp://aff.ironsocket.com/SH7L\nhttp://aff.ironsocket.com/SH7L\nhttp://ads.wsrs.net/www/delivery/ck.php?n=MyIPdb5f512\nhttp://wsrs.net/\nhttp://cmsgear.com/\n" + + getweblinks.getLinks(soup) + self.assertEqual(sys.stdout.getvalue(),data) + + +if __name__ == '__main__': + unittest.main()