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目录下的所有直接子目录和文件的名称(均不包含完整路径),如 >> ...
随机推荐
- Maven 报错:Compilation of Maven projects is supported only if external build is started from an IDE.
Maven 报错: Error:Maven Resources Compiler: Maven project configuration required for module 'yourProje ...
- Spring Boot 日志管理
Spring Boot 日志管理 网址 Spring Boot 日志管理 http://blog.didispace.com/springbootlog/ Spring Boot快速入门(四)--日志 ...
- 图像处理基本工具——Python 环境下的 Pillow( PIL )
由于笔者近期的研究课题与图像后处理有关,需要通过图像处理工具对图像进行变换和处理,进而生成合适的训练图像数据.该系列文章即主要记录笔者在不同的环境下进行图像处理时常用的工具和库.在 Python 环境 ...
- js定时器关闭,js定时器停止,一次关闭所有正在运行的定时器,自定义函数clearIntervals()一次关闭所有正在运行的定时器
js定时器关闭,一次关闭所有正在运行的定时器,自定义函数clearIntervals()一次关闭所有正在运行的定时器,原理:利用数组存储定时器id,然后遍历数组,关闭定时器 附上页面的截图,代码在截图 ...
- react native iOS真机调试-联网问题与js严格模式
rn:strict mode does not allow function declarations in a lexically nested statement https://blog.csd ...
- round.606.div2
A. Happy Birthday, Polycarp! 这个题意我确实没有看懂. 沃日,我懂了,我感觉我似乎都能切掉这题. B. Make Them Odd 这个我也能看懂.
- Xamarin.Forms之样式
使用XAML样式设置Xamarin.Forms应用的样式Xamarin.Forms应用程序的样式传统上是通过使用Style类将一组属性值分组到一个对象中来完成的,然后可以将其应用于多个视觉元素实例. ...
- 使用plotly dash-component-boilerplate 生成自己的组件
plotly 基于dash-component-boilerplate给我们提供了可以快速生成基于使用python 调用的react 组件 以下是一个简单的使用脚手架生成一个组件,同时可以了解组件的工 ...
- 05-树8 File Transfer (25 分)
We have a network of computers and a list of bi-directional connections. Each of these connections a ...
- 第09组 Alpha冲刺(1/6)
队名:观光队 组长博客 作业博客 组员实践情况 王耀鑫 过去两天完成了哪些任务 文字/口头描述 完成服务器连接数据库部分代码 展示GitHub当日代码/文档签入记录 接下来的计划 与服务器连接,配合前 ...