python获取https并且写文件日志
# -*- coding: utf-8 -*-
import os
import os.path
import shutil
import chardet
import urllib.request
import http.cookiejar
import ssl
import time
import datetime
import codecs
import socket def get_url_context_https():
url="https://120.198.253.63:8094/gds/platform/version/GetVersion.mt?osname=Android&type=2"
#ssl.socket.settimeout(5)
context = ssl._create_unverified_context()
#res_two = urllib.request.urlopen(url)
#code_two = res_two.getcode()
#html_two = res_two.read().decode('utf-8')
request=urllib.request.Request(url)
response=urllib.request.urlopen(url=request,context=context)
#print('网页状态码:%s' % (code_two))
#print('网页内容:'+html_two)
#print (response.read().decode('utf-8'))
print ("https 获取成功")
return True def get_url_context_http():
try:
url="xxx"
#ssl.socket.settimeout(5)
#context = ssl._create_unverified_context()
response = urllib.request.urlopen(url)
code_two = response.getcode()
html_two = response.read().decode('utf-8')
#request=urllib.request.Request(url)
#response=urllib.request.urlopen(url=request,context=context)
#print('网页状态码:%s' % (code_two))
#print('网页内容:'+html_two)
#print (response.read().decode('utf-8'))
return "http 获取成功"
except Exception as err:
return "http:"+str(err) file_path="E:\\doc\\py\\test\\get_page_log.txt"
cc=""
i=1
while(i<3600):
fw=open(file_path,"a+",encoding="utf-8") #r,w,a+ #,"utf-8"
try:
cc=""
cc=cc+"\r\n"+str(datetime.datetime.now())
print(datetime.datetime.now())
if(get_url_context_https()):
cc=cc+"\r\n"+"网页获取成功"
else:
cc=cc+"\r\n"+"网页获取失败"
except Exception as err:
cc=cc+"\r\n"+str(err)
print(err)
hcc=get_url_context_http();
cc=cc+"\r\n"+hcc
print(hcc)
finally:
print(datetime.datetime.now())
print("================"+str(i)+"================")
cc=cc+"\r\n"+str(datetime.datetime.now())
cc=cc+"\r\n"+"================"+str(i)+"================"
fw.write(cc)
fw.close()
i=i+1
time.sleep(1)
python获取https并且写文件日志的更多相关文章
- Log4net 写文件日志与数据库日志
一.数据库日志表结构 CREATE TABLE [dbo].[WebLog_Msg]( [LogID] [int] IDENTITY(1,1) NOT NULL, [Date] [datetime] ...
- python 获取导入模块的文件路径
接触到项目上有人写好的模块进行了导入,想查看模块的具体内容是如何实现的,需要找到模块的源文件. 本博文介绍两种查找模块文件路径方法: 方法一: #!/usr/bin/python # -*- codi ...
- python获取目录下所有文件
#方法1:使用os.listdir import os for filename in os.listdir(r'c:\\windows'): print filename #方法2:使用glob模块 ...
- 使用python+xpath 获取https://pypi.python.org/pypi/lxml/2.3/的下载链接
使用python+xpath 获取https://pypi.python.org/pypi/lxml/2.3/的下载链接: 使用requests获取html后,分析html中的标签发现所需要的链接在& ...
- python 获取当前目录下文件(转)
今天继续整理原来写的 python 代码,下面是获取文件信息的 python 处理代码. 获取指定目录下文件的文件名以及文件的数量,然后列出其中还存在的目录名称: #!/usr/bin/env pyt ...
- python获取当前文件路径
python获取当前文件路径 学习了:https://www.cnblogs.com/strongYaYa/p/7200357.html https://blog.csdn.net/heatdeath ...
- python获取文件路径
摘自:https://blog.csdn.net/Poo_Chai/article/details/89764001 import os root_path = os.path.abspath(os. ...
- Python获取当前脚本文件夹(Script)的绝对路径
Python获取当前脚本绝对路径 Python脚本有一个毛病,当使用相对路径时,被另一个不同目录下的py文件中导入时,会报找不到对应文件的问题.感觉是当前工作目录变成了导入py文件当前目录.如果你有配 ...
- Python获取目录、文件的注意事项
Python获取指定路径下的子目录和文件有两种方法: os.listdir(dir)和os.walk(dir),前者列出dir目录下的所有直接子目录和文件的名称(均不包含完整路径),如 >> ...
随机推荐
- 项目Beta冲刺(团队)——05.25(3/7)
项目Beta冲刺(团队)--05.25(3/7) 格式描述 课程名称:软件工程1916|W(福州大学) 作业要求:项目Beta冲刺(团队) 团队名称:为了交项目干杯 作业目标:记录Beta敏捷冲刺第3 ...
- new的模拟实现
new 一句话介绍 new: new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象类型之一 也许有点难懂,我们在模拟 new 之前,先看看 new 实现了哪些功能. 举个例子: // ...
- PHP:ThinkCMFX任意文件包含漏洞
前言:最近爆出来的漏洞,ThinkCmfX版本应该是通杀的,基于3.X Thinkphp开发的 代码下载地址:https://gitee.com/thinkcmf/ThinkCMFX/releases ...
- Feign发送Get请求时,采用POJO对象传递参数的最终解决方案 Request method 'POST' not supported (附带其余好几个坑)
yml: feign: httpclient: enabled: true properties: #feign feign.httpclient.enabled=true <!-- https ...
- Ansible自动部署lnmp架构+上线电商
1.首先准备3台机器 ansible机器:192.168.52.34 目标主机:192.168.52.35 目标主机:192.168.52.36 2.关闭防火墙 [root@localhost ~]# ...
- solidworks 学习 (二)
洗手液瓶建模
- nodegui 使用react开发跨平台应用试用
nodegui官方团队提供了基于react 应用开发方式,同时我们集成官方的packer 进行快速的应用打包 项目说明 项目使用了官方的计算机应用,我使用官方的react starter,同时添加了p ...
- 发布jar包到远端github仓库使用(将github仓库当作maven仓库)
今天把单点登陆的core模块搬到了github仓库 并且利用github仓库作为maven仓库 在项目中进行了引用 1. 起初看技术博客没有完全引入进来,调整了一下OK了 2. 还可以将其他模块或者工 ...
- FTO Obesity Variant Circuitry and Adipocyte Browning in Humans
好文献非常难得,提供了核心的研究思路. FTO Obesity Variant Circuitry and Adipocyte Browning in Humans - 这篇文章需要好好的解析 为深入 ...
- 关于使用sudo找不到环境变量的问题
参考这里:https://www.cnblogs.com/zhongshiqiang/p/10839666.html 使用sudo -E 保留当前用户环境,这时就不会存在找不到环境变量的问题了.