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 ...
随机推荐
- OpenSesame:一个能够攻击fixed-pin设备的工具
OpenSesame是一种设备,这种设备可以通过无线技术来打开任何一个设有固定密码的车库门,我从中发现了一个攻击无线固定pin码设备的新方法. 演示视频以及详细信息: opensesame源代码:ht ...
- php大力力 [002节]mac php环境安装,mamp安装 ,phpMyAdmin启动
php大力力 [002节]mac php环境安装,mamp安装 ,phpMyAdmin启动 每个人机器不一样,我手头是个air book,查了一下现在最好在mac下,用mamp, mamp百科介绍 , ...
- go 函数
GO 程序设计 函数 1.新的数据类型 mytype 用户可以根据自身需要定义新的数据类型,下面的mytype就是新定义的数据类型,其中第二个是一个结构体,结构体在go语言中是非常有用的数据类型, ...
- CRM客户关系管理系统修改(十四)
修改的流程:
- git pull --rebase 做了什么? 以及 Cannot rebase: You have unstaged changes 解决办法
最近刚学 git rebase,觉得很牛逼的样子, 结果今天就被打脸了. git pull --rebase 报错: Cannot rebase: You have unstaged changes ...
- C#不安全代码和指针
从通常情况下来看,为了保持类型安全,默认情况C# 不支持指针算法. 不过,当你需要使用指针的时候,请通过使用 unsafe 关键字,可以定义可使用指针的不安全上下文. 有关指针的更多信息,请参见主题指 ...
- EXT遮罩效果
<link href="/resources/ext/resources/css/ext-all.css" rel="stylesheet" type=& ...
- 转:去掉DataTable重复数据(程序示例比较)
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.T ...
- 转:Repeater嵌套绑定Repeater以及内层调用外层数据
<table border=" style="margin-bottom: 5px" width="100%"> <asp:Repe ...
- LeetCode Rotate Image (模拟)
题意: 将一个n*n的矩阵顺时针旋转90度. 思路: 都是差不多的思路,交换3次也行,反转再交换也是行的. class Solution { public: void rotate(vector< ...