File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ import urllib .request
2
+ import re
3
+
4
+
5
+ def load_file (path ):
6
+ with open (path , 'r' ) as file :
7
+ data = file .read ().replace ('\n ' , '' )
8
+ return data
9
+
10
+
11
+ if __name__ == '__main__' :
12
+ text = load_file ('README.md' )
13
+ s = re .findall ('\((.*?)\)' ,text )
14
+
15
+ broken_links = list ()
16
+ for link in s :
17
+ try :
18
+ conn = urllib .request .urlopen (link )
19
+ except urllib .error .HTTPError as e :
20
+ print ('HTTPError: {}' .format (e .code ) + ', ' + link )
21
+ broken_links .append (link )
22
+ except urllib .error .URLError as e :
23
+ print ('URLError: {}' .format (e .reason ) + ', ' + link )
24
+ except ValueError as e :
25
+ print ('ValueError: {}' .format (e ) + ', ' + link )
26
+ else :
27
+ print ('good' + ', ' + link )
28
+
29
+ with open ('broken_links.txt' , 'w' ) as f :
30
+ for line in broken_links :
31
+ f .write (f"{ line } \n " )
You can’t perform that action at this time.
0 commit comments