python实现蜘蛛功能批量下载手机壁纸
生活随笔
收集整理的這篇文章主要介紹了
python实现蜘蛛功能批量下载手机壁纸
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在百度貼吧發現一些比較好看的手機壁紙,想下載來用用,但是一張張保存覺得太麻煩,所以寫個python程序來批量爬取下載圖片。
要爬取的頁面http://tieba.baidu.com/p/1904141161?pid=24952618510#24952618510
程序代碼:
#!/usr/bin/env 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) imglist=re.findall(imgre,html) x=0 for imgre in imglist: urllib.urlretrieve(imgre,'%s.jpg'%x) x+=1 html=getHtml("http://tieba.baidu.com/p/1904141161?pid=24952618510#24952618510") print getImg(html)下載成功,隨便打開一個效果還不錯,玩的開心!
轉載于:https://blog.51cto.com/laoxu/1289792
總結
以上是生活随笔為你收集整理的python实现蜘蛛功能批量下载手机壁纸的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ScalaTest学习笔记(一)
- 下一篇: [Python学习记录]——Hello