码迷,mamicode.com
首页 > 编程语言 > 详细

python抓取网页信息

时间:2014-09-25 11:29:58      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   for   div   sp   2014   on   

环境: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

 

python抓取网页信息

标签:style   blog   http   color   for   div   sp   2014   on   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!