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目录下的所有直接子目录和文件的名称(均不包含完整路径),如 >> ...
 
随机推荐
- Spring Cloud 之 Feign 知识点:封装了 REST 调用
			
Feign Client 会在底层根据你的注解,跟你指定的服务建立连接.构造请求.发起请求.获取响应.解析响应,等等. Feign 的一个关键机制就是使用了动态代理. 首先,如果你对某个接口定义了 @ ...
 - 原生js的常用方法总结
			
=============== 通知: 博主已迁至<掘金>码字,博客园可能以后不再更新,掘金地址:https://juejin.im/post/5a1a6a6551882534af25a8 ...
 - C#中集合ArrayList与Hashtable的使用
			
C#中集合ArrayList与Hashtable的使用 http://blog.csdn.net/linukey/article/details/42506819 ArrayList: 一. 注意事项 ...
 - Helm 安装Nginx Ingress
			
为了便于将集群中的服务暴露到集群外部,需要使用Ingress.接下来使用Helm将Nginx Ingress部署到Kubernetes上. Nginx Ingress Controller被部署在Ku ...
 - Intellij IDEA如何生成JavaDoc
			
JavaDoc是一种将注释生成HTML文档的技术. 1.使用javadoc命令生成文档 首先了解一下javadoc指令的用法 用法: javadoc [options] [packagenames] ...
 - 关于Java锁(学习笔记)
			
个人学习笔记! 1)分布式锁的实现?①数据库实现单点.非重入.非阻塞.无失效时间.依赖数据库(要自己设置,可结合排它锁.乐观锁.悲观锁等混合使用)②缓存(Redis等)集群部署解决单点问题.分布式锁方 ...
 - 【luogu 5395】 【模板】第二类斯特林数·行
			
code: #include <bits/stdc++.h> #define ll long long #define setIO(s) freopen(s".in", ...
 - BZOJ 3561: DZY Loves Math VI  莫比乌斯反演+复杂度分析
			
推到了一个推不下去的形式,然后就不会了 ~ 看题解后傻了:我推的是对的,推不下去是因为不需要再推了. 复杂度看似很大,但其实是均摊 $O(n)$ 的,看来分析复杂度也是一个能力啊 ~ code: #i ...
 - LeetCode 865. Smallest Subtree with all the Deepest Nodes
			
原题链接在这里:https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/ 题目: Given a binar ...
 - 关于singer elt 的几篇很不错的文章
			
以下是链接来自singer 团队的实践,很不错,值得学习 参考连接 https://www.stitchdata.com/blog/100-billion-records-later-refining ...