-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_http_response.py
53 lines (42 loc) · 1.31 KB
/
check_http_response.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
48
49
50
51
52
53
import sys
import os
import requests
def script_path():
'''set current path to script_path'''
current_path = os.path.realpath(os.path.dirname(sys.argv[0]))
os.chdir(current_path)
return current_path
def simple_read(file):
with open(file, 'r') as f:
data = f.read().splitlines()
f.close()
return data
def simple_write(file, data):
'''simple_write data to .txt file, with specified data'''
with open(file, "w") as f:
f.write(str(data) + "\n")
f.close()
return True
def get_content(url):
try:
res = requests.get(url)
content = res.text
status = res.status_code
except:
content = ''
status = 0
return content, status
if __name__ == "__main__":
script_path()
file = 'urls.txt'
data = simple_read(file)
# urls = [item.split('|')[0] for item in data] # just parse in some way
urls = ['http://' + url for url in urls]
responseOk = []
for key, url in enumerate(urls):
content, status = get_content(url)
print("{}. <{}> --> {}".format(key, status, url))
# check if response is positive(set proper filter
if not status in (0, 404):
responseOk.append(url)
simple_write('out.txt', '\n'.join(responseOk))