python抓取网页信息

时间:2014-09-25 10:04:29   收藏:0   阅读:332

环境:python 2.7

用自带的urllib,urllib2包可以实现大部分抓取功能。代码十分简短。

关键在于正则表达式的建立和处理。

 1 #coding=utf-8
 2 ‘‘‘
 3 Created on 2014-9-25
 4 
 5 @author: Administrator
 6 ‘‘‘
 7 import urllib
 8 import urllib2
 9 import re
10 
11 #url = ‘http://www.taobao.com/‘
12 url = http://www.gov.cn/
13 
14 req = urllib2.Request(url)
15 html = urllib2.urlopen(req).read()
16 #print html
17 
18 ss = re.findall(blank">(.*?)\<\/,html)
19 for i in ss:
20     print i

 

原文:http://www.cnblogs.com/lovecc/p/3992046.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!