File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,10 +31,15 @@ def getLinks(soup,ext):
3131 print (bcolors .OKGREEN + 'Websites Found - ' + bcolors .ENDC + str (len (websites )))
3232 print ('-------------------------------' )
3333 for web in websites :
34- if (urllib .request .urlopen (web ).getcode () == 200 ):
35- print (web )
36- else :
37- print (bcolors .On_Red + web + bcolors .ENDC )
34+ flag = 1
35+ try :
36+ urllib .request .urlopen (web )
37+ except urllib .error .HTTPError as e :
38+ if e .code :
39+ print (bcolors .On_Red + web + bcolors .ENDC )
40+ flag = 0
41+ if flag :
42+ print (web )
3843 return websites
3944 else :
4045 raise ('Method parameter is not of instance bs4.BeautifulSoup' )
Original file line number Diff line number Diff line change @@ -13,12 +13,13 @@ class getLinksTestCase(unittest.TestCase):
1313
1414 def setUp (self ):
1515 self .held , sys .stdout = sys .stdout , StringIO ()
16+ self .maxDiff = None
1617
1718 def test_print_links (self ):
1819 #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"
19- data = "\n " + bcolors .OKGREEN + "Websites Found - " + bcolors .ENDC + "0 \n -------------------------------\n "
20-
21- getweblinks .getLinks (soup )
20+ data = "\n " + bcolors .OKGREEN + "Websites Found - " + bcolors .ENDC + "1 \n -------------------------------\n http://cmsgear.com/ \n "
21+ ext = [ '.com/' ]
22+ getweblinks .getLinks (soup , ext )
2223 self .assertEqual (sys .stdout .getvalue (),data )
2324
2425
You can’t perform that action at this time.
0 commit comments