#coding: utf-8#@name 获取指定URL地址的响应内容#@author hwliang(hwl@bt.cn)#@print stringimport osimport sysos.chdir('/www/server/panel')sys.path.insert(0,'class/')import publicimport requestsurl = 'https://www.baidu.com/'try:#去掉HTTPS的证书环节req_status = requests.get(url,timeout=30,verify=False)content = req_status.text # 获取响应内容的文本部分first_50_chars = content[:50] # 提取前50个字符first_150_chars = content[:150] # 提取前50个字符#获取状态 print(req_status.status_code)msg = 'baidu.com状态是:' + str(req_status.status_code) +';\n200(成功);400(错误请求) ;\n' + first_50_charsmsg2 = 'baidu.com状态是:' + str(req_status.status_code) +";\n200(成功);400(错误请求) ;\n" + first_150_chars#发送公众号 200(成功) 服务器已成功处理了请求。通常,这表示服务器提供了请求的网页. 400(错误请求) 服务器不理解请求的语法res_msg = public.push_msg('wx_account',{'msg':msg})#企业微信res_msg2 = public.push_msg('weixin',{'msg':msg2})if 'status' in res_msg and res_msg['status']:print("done")else:print('发送情况:')print(res_msg)except Exception as ex:print('异常:')print(ex)sys.exit(1)摘要:#coding: utf-8#@name 获取指定URL地址的响应内容#@author hwliang(hwl@bt.cn)#@print stringimport osimport sysos.chdir('/www/server/panel')sys.pa
来源:孙晏欣
免责声明:本站系转载,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权和其它问题,请在30日内与本站联系,我们将在第一时间删除内容!