-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
url_checker.py
47 lines (39 loc) · 1.14 KB
/
url_checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import re
import requests
def exists(path):
""" Utility function to check whether a web file exists
:param path:
:return:
"""
r = requests.head(path)
# print(r.status_code)
return r.status_code == requests.codes.ok
def exists_adv(path):
""" Utility function to check whether a web file exists
:param path:
:return:
"""
# TODO: use selenium
r = requests.head(path)
# print(r.status_code)
return r.status_code == requests.codes.ok
if __name__ == "__main__":
# driver = webdriver.Firefox()
manual_links = []
potential_broken_links = []
with open('README_11232019.md', encoding="utf-8") as f:
lines = f.readlines()
for line in lines:
result = re.search(']\(http(.*)\)', line)
if result:
link = "http" + result.group(1)
if "github" in link or "coursera" in link:
manual_links.append(link)
else:
flag = exists(link)
if not flag:
potential_broken_links.append(link)
print(link)
print()
for link in manual_links:
print(link)