Skip to content

Commit 8e05a5c

Browse files
requests the url, get the http response code , if the code is 200, open the url on browser
1 parent cf71c63 commit 8e05a5c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

findsth.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import webbrowser
2+
import sys
3+
import requests
4+
import logging
5+
6+
protocol='http'
7+
topDomainName=['.com','.cn','.net','.de','.fi','.co.jp', '.ru']
8+
argv=sys.argv[1:]
9+
print(argv)
10+
11+
logging.basicConfig(level=logging.INFO)
12+
urls=[]
13+
for i in range(len(topDomainName)):
14+
aTop=topDomainName[i]
15+
for j in range(len(argv)):
16+
domainName=argv[j]
17+
url=protocol + '://' + 'www.' + domainName + aTop
18+
logging.info('url is: %s',url)
19+
try:
20+
req=requests.get(url, timeout=10)
21+
code=req.status_code
22+
except requests.exceptions.ReadTimeout:
23+
code=-1
24+
except requests.exceptions.ConnectionError:
25+
code=-1
26+
except requests.exceptions.TooManyRedirects:
27+
code=-1
28+
logging.info('code is: %d',code)
29+
if code == 200:
30+
urls.append(url)
31+
logging.info('Available url:%s',url)
32+
33+
for i in range(len(urls)):
34+
logging.info('Openning: %s',urls[i])
35+
webbrowser.open_new_tab(urls[i])
36+
#webbrowser.open_new_tab(url)
37+

0 commit comments

Comments
 (0)