Python2 name Python3 nameurllib.urlopen() urllib.request.urlopen()urllib2.urlopen() urllib.request.urlopen()urllib.urlretrieve() urllib.request.urlret...
分类:
编程语言 时间:
2014-10-15 18:27:35
阅读次数:
252
简介:urllib2是python的一个获取url(Uniform Resource Locators,统一资源定址器)的模块。它用urlopen函数的形式提供了一个非常简洁的接口。这使得用各种各样的协议获取url成为可能。它同时 也提供了一个稍微复杂的接口来处理常见的状况-如基本的认证,cooki...
分类:
编程语言 时间:
2014-10-13 18:29:17
阅读次数:
185
工作中需要判断某个文本中的URL是否能正常访问,并且随机获取其中N行能正常访问的URL数据,我的思路是:读取文本每一行数据,用urlopen访问,将返回状态码为200的URL保存到一个列表,获得列表长度,使用random产生一个随机值作为列表下标,获取该行数据。具体实现如下: 1 import ur...
分类:
编程语言 时间:
2014-10-13 17:10:39
阅读次数:
233
#!/usr/bin/python
import re
import urllib
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html
def getImg(html):
reg = r'src="(.*?\.jpg)" width'
imgre = re.compile(reg)
...
分类:
编程语言 时间:
2014-10-11 23:57:32
阅读次数:
211
1.[代码]最基本的抓站 ?12import urllib2content = urllib2.urlopen('http://XXXX').read()2.[代码]使用代理服务器 ?12345import urllib2proxy_support = urllib2.ProxyHandler({'...
分类:
编程语言 时间:
2014-10-10 19:32:24
阅读次数:
226
ctrl+`importurllib2,os;pf=‘Package
Control.sublime-package‘;ipp=sublime.installed_packages_path();os.makedirs(ipp)
ifnotos.path.exists(ipp)else
None;open(os.path.join(ipp,pf),‘wb‘).write(urllib2.urlopen(‘http://sublime.wbond.net/‘+pf.replace(‘
‘,‘%20‘)).rea..
分类:
其他好文 时间:
2014-10-09 16:40:58
阅读次数:
222
Python 中urllib2.urlopen 中存在中文转码问题,解决方法如下:1.import BeautifulSoupimport chardetresponse =urllib2.urlopen('%s'%line) #response.decode('utf-8')...
分类:
编程语言 时间:
2014-10-08 14:44:45
阅读次数:
176
python下读取一个页面的数据可以通过urllib2轻松实现请求import urllib2print urllib2.urlopen('http://www.baidu.com').read()涉及到页面的POST请求操作的话需要提供头信息,提交的post数据和请求页面。其中的post数据需要u...
分类:
编程语言 时间:
2014-10-05 05:27:27
阅读次数:
201
1、获取web页面#coding:utf-8import sys,urllib2req=urllib2.Request(sys.argv[1])fd=urllib2.urlopen(req)while 1: data=fd.read(1024) if not len(data): ...
分类:
Web程序 时间:
2014-09-30 14:31:59
阅读次数:
147
#!coding:utf-8# 获取web页面import sys,urllib2req=urllib2.Request(sys.argv[1])fd=urllib2.urlopen(req)while 1: data=fd.read() if not len(data): ...
分类:
编程语言 时间:
2014-09-29 16:42:11
阅读次数:
165