打赏

星辰大海ゞ

That which does not kill us makes us stronger!

导航

Python爬虫示例

 1 #!/usr/bin/python
 2 #coding:utf8
 3 import re
 4 import urllib
 5 
 6 def gethtml(url):
 7     page=urllib.urlopen(url)
 8     html=page.read()
 9     return html
10 
11 def getimg(html):
12     reg=r'<img src="(http.*?\.gif)" alt'
13     imgre=re.compile(reg)
14     imglist=re.findall(imgre,html)
15     ii=0
16     for imgimg in imglist:
17         urllib.urlretrieve(imgimg,'%s.jpg' % ii)
18         ii+=1
19 
20 aa=gethtml('http://www.126.com')
21 print getimg(aa)
View Code

 

posted on 2014-05-10 09:36  星辰大海ゞ  阅读(299)  评论(0编辑  收藏  举报