白天的影子

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

2019年7月31日

摘要: 需求:Python检测URL状态,并追加保存200的URL 代码一: #! /usr/bin/env python #coding=utf-8 import sys import requests def getHttpStatusCode(url): try: request = requests.get(url) httpStatusCode = request.status_code return httpStatusCode except requests.exceptions.HTTPError as e: return e if __name__ == "__main__": with open('1.txt', 'r') as f: for line in f: try: status = getHttpStatusCo 阅读全文
posted @ 2019-07-31 11:30 白天的影子 阅读(1008) 评论(0) 推荐(0)

摘要: Python开发中时长遇到要下载文件的情况,最常用的方法就是通过Http利用urllib或者urllib2模块,此外Python还提供了另外一种方法requests。 下面来看看三种方法是如何来下载文件的: 方法一: import urllib print "downloading with urllib" url = 'http://download.redis.io/releases/redis-5.0.5.tar.gz' print "downloading with urllib" urllib.urlretrieve(url, "demo.zip") 阅读全文
posted @ 2019-07-31 10:39 白天的影子 阅读(53413) 评论(0) 推荐(1)