本文主要通过Python爬取百度壁纸的图片
程序代码:
import urllib
import re
def GetHtml(url):
page = urllib.urlopen(url)
html = page.read();
return html
def GetImg(html):
reg = '"((http|ftp)s?://.*?)"'
imgre = re.compile(reg)
imglist = re.findall(imgre,html)
x=0
for imgurl in imglist:
str=imgurl[0]
if str.find(".jpg")==-1:
continue
try:
urllib.urlretrieve(str,"%s.jpg"% x)
x+=1
except :
continue
def ReadHtmlText(urlStr):
html = urllib.urlopen(urlStr)
print(html.read())
htmltex=GetHtml("http://image.baidu.com/search/index?ct=201326592&tn=baiduimage&word=%E5%A3%81%E7%BA%B8%20%E4%B8%8D%E5%90%8C%E9%A3%8E%E6%A0%BC%20%E7%BE%8E%E5%A5%B3&pn=0&ie=utf-8&oe=utf-8&cl=2&lm=-1&fr=ala&se=&sme=")
print GetImg(htmltex)