1. # -*- coding: utf-8 -*-
  2. import os
  3. import os.path
  4. import shutil
  5. import chardet
  6. import urllib.request
  7. import http.cookiejar
  8. import ssl
  9. import time
  10. import datetime
  11. import codecs
  12. import socket
  13.  
  14. def get_url_context_https():
  15. url="https://120.198.253.63:8094/gds/platform/version/GetVersion.mt?osname=Android&type=2"
  16. #ssl.socket.settimeout(5)
  17. context = ssl._create_unverified_context()
  18. #res_two = urllib.request.urlopen(url)
  19. #code_two = res_two.getcode()
  20. #html_two = res_two.read().decode('utf-8')
  21. request=urllib.request.Request(url)
  22. response=urllib.request.urlopen(url=request,context=context)
  23. #print('网页状态码:%s' % (code_two))
  24. #print('网页内容:'+html_two)
  25. #print (response.read().decode('utf-8'))
  26. print ("https 获取成功")
  27. return True
  28.  
  29. def get_url_context_http():
  30. try:
  31. url="xxx"
  32. #ssl.socket.settimeout(5)
  33. #context = ssl._create_unverified_context()
  34. response = urllib.request.urlopen(url)
  35. code_two = response.getcode()
  36. html_two = response.read().decode('utf-8')
  37. #request=urllib.request.Request(url)
  38. #response=urllib.request.urlopen(url=request,context=context)
  39. #print('网页状态码:%s' % (code_two))
  40. #print('网页内容:'+html_two)
  41. #print (response.read().decode('utf-8'))
  42. return "http 获取成功"
  43. except Exception as err:
  44. return "http:"+str(err)
  45.  
  46. file_path="E:\\doc\\py\\test\\get_page_log.txt"
  47. cc=""
  48. i=1
  49. while(i<3600):
  50. fw=open(file_path,"a+",encoding="utf-8") #r,w,a+ #,"utf-8"
  51. try:
  52. cc=""
  53. cc=cc+"\r\n"+str(datetime.datetime.now())
  54. print(datetime.datetime.now())
  55. if(get_url_context_https()):
  56. cc=cc+"\r\n"+"网页获取成功"
  57. else:
  58. cc=cc+"\r\n"+"网页获取失败"
  59. except Exception as err:
  60. cc=cc+"\r\n"+str(err)
  61. print(err)
  62. hcc=get_url_context_http();
  63. cc=cc+"\r\n"+hcc
  64. print(hcc)
  65. finally:
  66. print(datetime.datetime.now())
  67. print("================"+str(i)+"================")
  68. cc=cc+"\r\n"+str(datetime.datetime.now())
  69. cc=cc+"\r\n"+"================"+str(i)+"================"
  70. fw.write(cc)
  71. fw.close()
  72. i=i+1
  73. time.sleep(1)

python获取https并且写文件日志的更多相关文章

  1. Log4net 写文件日志与数据库日志

    一.数据库日志表结构 CREATE TABLE [dbo].[WebLog_Msg]( [LogID] [int] IDENTITY(1,1) NOT NULL, [Date] [datetime]  ...

  2. python 获取导入模块的文件路径

    接触到项目上有人写好的模块进行了导入,想查看模块的具体内容是如何实现的,需要找到模块的源文件. 本博文介绍两种查找模块文件路径方法: 方法一: #!/usr/bin/python # -*- codi ...

  3. python获取目录下所有文件

    #方法1:使用os.listdir import os for filename in os.listdir(r'c:\\windows'): print filename #方法2:使用glob模块 ...

  4. 使用python+xpath 获取https://pypi.python.org/pypi/lxml/2.3/的下载链接

    使用python+xpath 获取https://pypi.python.org/pypi/lxml/2.3/的下载链接: 使用requests获取html后,分析html中的标签发现所需要的链接在& ...

  5. python 获取当前目录下文件(转)

    今天继续整理原来写的 python 代码,下面是获取文件信息的 python 处理代码. 获取指定目录下文件的文件名以及文件的数量,然后列出其中还存在的目录名称: #!/usr/bin/env pyt ...

  6. python获取当前文件路径

    python获取当前文件路径 学习了:https://www.cnblogs.com/strongYaYa/p/7200357.html https://blog.csdn.net/heatdeath ...

  7. python获取文件路径

    摘自:https://blog.csdn.net/Poo_Chai/article/details/89764001 import os root_path = os.path.abspath(os. ...

  8. Python获取当前脚本文件夹(Script)的绝对路径

    Python获取当前脚本绝对路径 Python脚本有一个毛病,当使用相对路径时,被另一个不同目录下的py文件中导入时,会报找不到对应文件的问题.感觉是当前工作目录变成了导入py文件当前目录.如果你有配 ...

  9. Python获取目录、文件的注意事项

    Python获取指定路径下的子目录和文件有两种方法: os.listdir(dir)和os.walk(dir),前者列出dir目录下的所有直接子目录和文件的名称(均不包含完整路径),如 >> ...

随机推荐

  1. 关于Python文件读写

    Python中文件操作可以通过open函数,这的确很像C语言中的fopen.通过open函数获取一个file object,然后调用read(),write()等方法对文件进行读写操作. 1.open ...

  2. linux下如何完全删除用户

    1.首先进入系统创建一个用户 [root@localhost /]# useradd haha   #创建用户  haha是用户名 [root@localhost /]# passwd haha    ...

  3. 在jsp中获取SpringSecurity中已登录的用户的用户名

    1.先引入secrity的标签库 <%@ taglib prefix="security" uri="http://www.springframework.org/ ...

  4. 电脑按键混乱,好像被锁定了Alt键

    在知乎上找到一篇文章,https://zhuanlan.zhihu.com/p/34835461 解决了我的问题,解决办法是按住左右两边的alt+shift+ctrl

  5. [RN] React Native 使用 AsyncStorage 存储 缓存数据

    React Native 使用 AsyncStorage 存储 缓存数据 AsyncStorage是一个简单的.异步的.持久化的Key-Value存储系统,它对于App来说是全局性的.这是官网上对它的 ...

  6. 洛谷 P3371【模板】单源最短路径(弱化版)

    题面 既然是模板, 那就直接贴代码? 两种思路 1.迪杰斯特拉 #include <cstdio> #include <cstring> #include <iostre ...

  7. PHP入门之调试

    环境 开发工具VSCode 2019 代码库 自建git 仓库 win7集成环境 PHPStudy2018  具体设置信息:   PHP 5.4.45 ,MySql 5.7 , Apache 2.4 ...

  8. JAVA基础--MySQL(二)

     数据库约束 1.基础限制 ① 单一表内字节量总和不能超过65535,null 占用一个字节空间 ② varchar存储255 以内字节占用一个字节表示长度,255以上自己则占用两个字节表示长度 ③ ...

  9. 了解Vuex状态管理模式的理解强化指南

    1 Vuex是什么呢?它是Vue的状态管理模式,在使用vue的时候,需要在vue中各个组件之间传递值是很痛苦的,在vue中我们可以使用vuex来保存我们需要管理的状态值,值一旦被改变,所有引用该值的地 ...

  10. Lombok的使用详解与插件安装

    JAVA面向对象编程中的封闭性和安全性.封闭性即对类中的域变量进行封闭操作,即用private来修饰他们,如此一来其他类则不能对该变量访问.这样我们就将这些变量封闭在了类内部,这样就提高了数据的安全性 ...