html.parser?HTMLParser??
urllib.request?urlopen??
urllib?parse
LinkParser(HTMLParser):
????handle_starttag(,?tag,?attrs):
????????tag?==?:
????????????(key,?val...
分类:
编程语言 时间:
2015-10-29 01:00:57
阅读次数:
533
#爬取网站中的图片 1 import re #正则表达式库 2 import urllib #url链接库 3 4 def getHtml(url): 5 page = urllib.urlopen(url) #打开链接 6 html = page.read() ...
分类:
编程语言 时间:
2015-10-16 15:10:12
阅读次数:
278
今天用Python写了个简单的爬虫程序,抓取虎扑篮球(nba.hupu.com)的首页内容,代码如下:1 #coding:gb23122 import urllib2, re3 webpage = urllib2.urlopen('http://nba.hupu.com')4 text = webp...
分类:
编程语言 时间:
2015-10-15 01:12:49
阅读次数:
201
1.urllib2简介urllib2的是爬取URL(统一资源定位器)的Python模块。它提供了一个非常简单的接口,使用urlopen函数。它能够使用多种不同的协议来爬取URL。它还提供了一个稍微复杂的接口,用于处理常见的情况 - 如基本身份验证,cookies,代理等。2.抓取URLs使用urli...
分类:
编程语言 时间:
2015-10-13 22:28:04
阅读次数:
527
用python抓取指定页面:代码如下:import urllib.requesturl= "http://www.baidu.com"data = urllib.request.urlopen(url).read()#data = data.decode('UTF-8')print(data)url...
分类:
编程语言 时间:
2015-10-09 00:33:23
阅读次数:
329
新版python中,urllib和urllib2合并了,统一为urllib(1)简单爬取网页import urllibcontent = urllib.request.urlopen(req).read().decode("utf-8")(2)添加headerimport urllibreq = u...
分类:
编程语言 时间:
2015-10-03 14:20:07
阅读次数:
216
example: http://xyzp.haitou.cc/article/722427.html首先是直接下载好每个页面,可以使用 os.system( "wget "+str(url)) 或者urllib2.urlopen(url) ,很简单不赘述。然后,重头戏,进行信息抽取:#!/usr/....
分类:
数据库 时间:
2015-09-29 18:47:43
阅读次数:
190
#encoding=gb2312import urllibimport redef getHtml(url): page = urllib.urlopen(url) html = page.read() return htmldef getImg(html): reg = r...
分类:
编程语言 时间:
2015-09-29 07:38:59
阅读次数:
334
deftest3():
url="http://www.ip.cn"
proxy_handler=urllib2.ProxyHandler({‘http‘:‘http://username:password@host:port‘})
opener=urllib2.build_opener(proxy_handler);
urllib2.install_opener(opener)
conn=urllib2.urlopen(url)
printconn.read()
分类:
编程语言 时间:
2015-09-23 19:37:36
阅读次数:
202
下面我们创建一个真正的爬虫例子爬取我的博客园个人主页首页的推荐文章列表和地址scrape_home_articles.pyfrom urllib.request import urlopenfrom bs4 import BeautifulSoupimport rehtml = urlopen("h...
分类:
编程语言 时间:
2015-09-23 13:12:05
阅读次数:
208