urllib最常用的两大功能(个人理解urllib用于辅助urllib2) 1.urllib.urlopen() 2. urllib.urlencode() #适当的编码,可用于后面的post提交数据 urllib2常用的函数 1.最基本的打开读取一个网页 2.地址创建一个Request对象 3.D ...
分类:
Web程序 时间:
2016-05-18 01:35:29
阅读次数:
247
__author__=mkdir(path):
os
path=path.strip()path=path.rstrip()mkfile=os.path.exists(path)
mkfile:
()
:
os.makedirs(path)
()
urllib,urllib2,re
geturl(url):
file_lists=[]
req=urllib2.Request(url)
req.add_header(,
)
data=urllib2.urlopen(req)
f=data.read()
..
分类:
编程语言 时间:
2016-05-17 19:49:36
阅读次数:
261
使用urllib2访问页面:
import urllib2
import cookielib
url = "http://www.baidu.com"
print 'The first method : '
response1 = urllib2.urlopen(url)
print response1.getcode()
print len(response1.read())
print...
分类:
编程语言 时间:
2016-05-10 12:59:19
阅读次数:
336
一,获取整个页面数据Urllib模块提供了读取web页面数据的接口,我们可以像读取本地文件一样读取www和ftp上的数据。首先,我们定义了一个getHtml()函数:urllib.urlopen()方法用于打开一个URL地址。read()方法用于读取URL上的数据,向getHtml()函数传递一个网址,并把整个页面下..
分类:
编程语言 时间:
2016-05-09 18:57:37
阅读次数:
232
该小脚本实现对电影天堂网站的最新电影查找。frombs4importBeautifulSoup
importurllib
importre
url=‘http://www.ygdy8.net/html/gndy/dyzz/index.html‘
moive_url_list=[]
moive_name_list=[]
request=urllib.urlopen(url)
response=request.read()
response=unicode(respons..
分类:
编程语言 时间:
2016-05-09 07:15:15
阅读次数:
218
脚本一:#!/usr/bin/envpython
#coding:utf-8
frombs4importBeautifulSoup
importurllib
importre
art={}
forpageinrange(1,5):
page=str(page)
url=‘http://yujianglei.blog.51cto.com/all/7215578/page/‘+page
response=urllib.urlopen(url).read()
response=unicode(respons..
分类:
编程语言 时间:
2016-05-08 01:23:18
阅读次数:
205
初学python,所用python3.5,根据教程写代码,所抓取的网页为新浪博客中的一篇文章,在使用urllib.request.urlopen(url).read()的返回值时,发现content的类型为bytes,如果不进行类型转换的话,在python打印时是乱码。 解决方案是将content解 ...
分类:
编程语言 时间:
2016-05-04 22:30:17
阅读次数:
2394
用yum报错 http://mirrors.aliyun.com/centos/%24releasever/addons/x86_64/repodata/repomd.xml: [Errno 12] Timeout: <urlopen error timed out> Trying other mi ...
分类:
其他好文 时间:
2016-04-28 00:07:35
阅读次数:
176
1、urllib模块 1.urllib.urlopen(url[,data[,proxies]]) 打开一个url的方法,返回一个文件对象,然后可以进行类似文件对象的操作。本例试着打开google urlopen返回对象提供方法: - read() , readline() ,readlines() ...
分类:
编程语言 时间:
2016-04-22 11:55:43
阅读次数:
248
import urllib2response = urllib2.urlopen("http://www.baidu.com")print response.read() urlopen(url, data, timeout) 构造Requset import urllib2 request = u ...
分类:
Web程序 时间:
2016-04-14 15:40:38
阅读次数:
218