BeautifulSoup爬网页图片

#-*- coding: utf-8 -*-
import urllib2
import urllib
import os
from BeautifulSoup import BeautifulSoup def getAllImageLink():
# 需要下载图片的地址
html = urllib2.urlopen('http://www.win4000.com/meinvtag34.html').read()
soup = BeautifulSoup(html) liResult = soup.findAll('li',attrs={"class":"box"})
numberIndex = 0
for li in liResult:
imageEntityArray = li.findAll('img')
for image in imageEntityArray:
link = image.get('src')
imageName = 'image' + str(numberIndex)
numberIndex = numberIndex + 1
# 下载到的地址
filesavepath = 'C:\\Users\\Administrator\\Desktop\\py\\%s.jpg' % imageName
urllib.urlretrieve(link,filesavepath)
print filesavepath if __name__ == '__main__':
getAllImageLink()

  

上一篇:Tree Summing UVA - 112 二叉树


下一篇:org.apache.hadoop.security.AccessControlException: Permission denied: user=?, access=WRITE, inode="/":hadoop:supergroup:drwxr-xr-x 异常解决