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目录下的所有直接子目录和文件的名称(均不包含完整路径),如 >> ...
随机推荐
- 关于Python文件读写
Python中文件操作可以通过open函数,这的确很像C语言中的fopen.通过open函数获取一个file object,然后调用read(),write()等方法对文件进行读写操作. 1.open ...
- linux下如何完全删除用户
1.首先进入系统创建一个用户 [root@localhost /]# useradd haha #创建用户 haha是用户名 [root@localhost /]# passwd haha ...
- 在jsp中获取SpringSecurity中已登录的用户的用户名
1.先引入secrity的标签库 <%@ taglib prefix="security" uri="http://www.springframework.org/ ...
- 电脑按键混乱,好像被锁定了Alt键
在知乎上找到一篇文章,https://zhuanlan.zhihu.com/p/34835461 解决了我的问题,解决办法是按住左右两边的alt+shift+ctrl
- [RN] React Native 使用 AsyncStorage 存储 缓存数据
React Native 使用 AsyncStorage 存储 缓存数据 AsyncStorage是一个简单的.异步的.持久化的Key-Value存储系统,它对于App来说是全局性的.这是官网上对它的 ...
- 洛谷 P3371【模板】单源最短路径(弱化版)
题面 既然是模板, 那就直接贴代码? 两种思路 1.迪杰斯特拉 #include <cstdio> #include <cstring> #include <iostre ...
- PHP入门之调试
环境 开发工具VSCode 2019 代码库 自建git 仓库 win7集成环境 PHPStudy2018 具体设置信息: PHP 5.4.45 ,MySql 5.7 , Apache 2.4 ...
- JAVA基础--MySQL(二)
数据库约束 1.基础限制 ① 单一表内字节量总和不能超过65535,null 占用一个字节空间 ② varchar存储255 以内字节占用一个字节表示长度,255以上自己则占用两个字节表示长度 ③ ...
- 了解Vuex状态管理模式的理解强化指南
1 Vuex是什么呢?它是Vue的状态管理模式,在使用vue的时候,需要在vue中各个组件之间传递值是很痛苦的,在vue中我们可以使用vuex来保存我们需要管理的状态值,值一旦被改变,所有引用该值的地 ...
- Lombok的使用详解与插件安装
JAVA面向对象编程中的封闭性和安全性.封闭性即对类中的域变量进行封闭操作,即用private来修饰他们,如此一来其他类则不能对该变量访问.这样我们就将这些变量封闭在了类内部,这样就提高了数据的安全性 ...