File tree Expand file tree Collapse file tree
script_library/scripts/basic Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import urllib3
2+ urllib3 .disable_warnings ()
3+ def menu ():
4+ print ('-' * 20 )
5+ print ('网页侦测程序(GET请求)' )
6+ print ('http状态码含义:' )
7+ print ('1xx:信息,请求收到,继续处理。' )
8+ print ('2xx:成功,请求已成功被服务器接收、理解、并接受' )
9+ print ('3xx:重定向,需要后续操作才能完成这一请求' )
10+ print ('4xx:客户端错误,请求含有语法错误或者无法被执行' )
11+ print ('5xx:服务器错误,服务器在处理某个正确请求时发生错误' )
12+ print ('-' * 20 )
13+
14+ def url ():
15+ name_url = input ('请输入网名:' )
16+ web_url = input ('请输入网址:' )
17+
18+ if not web_url .startswith (('http://' , 'https://' )):
19+ web_url = 'http://' + web_url
20+
21+ try :
22+ http = urllib3 .PoolManager ()
23+ r = http .request ('GET' , web_url , timeout = 5.0 )
24+ print (name_url , '请求状态码:' , r .status )
25+ except Exception as e :
26+ print (f'请求失败: { e } ' )
27+
28+ def main ():
29+ menu ()
30+ while True :
31+ url ()
32+ # 添加退出选项
33+ choice = input ('是否继续检查?(y/n): ' ).lower ()
34+ if choice != 'y' :
35+ print ('程序结束' )
36+ break
37+
38+ if __name__ == "__main__" :
39+ main ()
40+
You can’t perform that action at this time.
0 commit comments