Python中urlretrieve函数
>>> import urllib.request
>>>local_filename,headers=urllib.request.urlretrieve('http://python.org/')
>>> html = open(local_filename)
>>> html.close()
#coding:utf-8
from urllib.request import urlretrieve def firstNonBlank(lines):
for eachLine in lines:
if not eachLine.strip():
continue
else:
return eachLine def firstLast(webpage):
f=open(webpage,encoding='utf-8')
lines=f.readlines()
f.close()
print(firstNonBlank(lines))
lines.reverse()
print(firstNonBlank(lines)) def download(url='http://www.baidu.com',process=firstLast):
try:
retval=urlretrieve(url)[0]
except IOError:
retval=None
if retval:
process(retval) if __name__=="__main__":
download()
Python中urlretrieve函数的更多相关文章
- Python urllib urlretrieve函数解析
Python urllib urlretrieve函数解析 利用urllib.request.urlretrieve函数下载文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 Ur ...
- Python中split()函数的用法及实际使用示例
Python中split()函数,通常用于将字符串切片并转换为列表. 一.函数说明: split():语法:str.split(str="",num=string.count(st ...
- Python中利用函数装饰器实现备忘功能
Python中利用函数装饰器实现备忘功能 这篇文章主要介绍了Python中利用函数装饰器实现备忘功能,同时还降到了利用装饰器来检查函数的递归.确保参数传递的正确,需要的朋友可以参考下 " ...
- python中range()函数的用法
python中range()函数可创建一个整数列表,一般用在for循环中. range()函数语法: range(start,stop[,step]) 参数说明: star: 计数从star开始.默认 ...
- Python 中的函数
学了 Python 中的数据类型,语句,接下来就来说一下 Python 中的函数,函数是结构化编程的核心.我们使用函数可以增加程序的可读性.自定义函数时使用关键字def 函数由多条语句组成.在定义函数 ...
- python中format函数
python中format函数用于字符串的格式化 通过关键字 1 print('{名字}今天{动作}'.format(名字='陈某某',动作='拍视频'))#通过关键字 2 grade = {'nam ...
- Python中readline()函数 去除换行符
从Python中readline()函数读取的一行内容中含有换行符\n,很多时候我们需要处理不含有换行符的字符串,此时就要去掉换行符\n. 方法是使用strip()函数. 例子如下: f = open ...
- Python中int()函数的用法浅析
int()是Python的一个内部函数 Python系统帮助里面是这么说的 >>> help(int) Help on class int in module __builti ...
- 【313】python 中 print 函数用法总结
参考:python 中 print 函数用法总结 参考:Python print() 函数(菜鸟教程) 参考:Python 3 print 函数用法总结 目录: 字符串和数值类型 变量 格式化输出 p ...
随机推荐
- libimobiledevice安装步骤
https://github.com/libimobiledevice/libimobiledevice libimobiledevice安装指南,你还不知道libimobiledevice为何物,赶 ...
- Note_Master-Detail Application(iOS template)_03_main.m
// main.m #import <UIKit/UIKit.h>//UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面( UI )接口.应用程序 ...
- bistu新生-1005
#include "stdio.h"#include "string.h"int main(){ char ku[]={'0','1','2','3','4', ...
- 无法为表空间 ***中的段创建 INITIAL 区
这是由于表空间不足引起的. 具体错误: 解决方案:扩展表空间
- Java custom annotations
Custom annotation definition is similar as Interface, just with @ in front. Annotation interface its ...
- Packages
Packages are a way of structuring Python's module namespace by using "dotted module names" ...
- iOS数据持久化
在iOS中,实现数据持久化一般分为4大种: 1.属性列表 2.对象归档 3.SQLite 4.Core Data 一.属性列表 NSUserDefaults类的使用和NSKeyedArchiver有很 ...
- 如何用JS获取ASP.net中的textbox的值 js获不到text值
<tr> <td class="table_body" style="width: 10%" a ...
- URAL 2040 (回文自动机)
Problem Palindromes and Super Abilities 2 (URAL2040) 题目大意 给一个字符串,从左到右依次添加,询问每添加一个字符,新增加的回文串数量. 解题分析 ...
- show master status empty解决方案
The following MySQL error might occur if you are using MySQL replication and binary logs. mysql> ...