-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsiteSorting.py
More file actions
53 lines (40 loc) · 1.29 KB
/
Copy pathwebsiteSorting.py
File metadata and controls
53 lines (40 loc) · 1.29 KB
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
from htmlextract import extractTxtFromHtml
from gpt_webtxtanalyst import GptWebsiteAnalyser
import requests
import time
with open("upip.txt","r") as f:
IPs = [line.strip() for line in f]
tooshort = 0
for ip in IPs:
try:
print('sending request...')
url = 'http://'+ ip +'/'
print(ip)
r = requests.get(url,allow_redirects=True)
redirect = r.url
if(redirect != url):
print('redirect detected : ' + redirect)
newurl = r.url
r = requests.get(newurl)
data = r.text
print(len(data))
if len(data) < 500:
tooshort = 1
if len(data) > 30000:
data = data[:30000]
if tooshort != 1:
dataExtracted = extractTxtFromHtml(data)
print('data extracted')
response = GptWebsiteAnalyser(dataExtracted)
print('Got response from GPT')
if len(response) > 0:
print(' : ' +response)
with open('labeled_wensites.txt','a') as p:
p.write(ip + ' : ' + response + '\n')
else:
print('gpt had enough')
else:
tooshort = 0
print('it was too short')
except Exception as e:
print(f"Error: {e}")