好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python抓取网页中的图片示例

代码如下:


#coding:utf8
import re
import urllib
def getHTML(url):
page = urllib.urlopen(url)
html = page.read()
return html

def getImg(html,imgType):
reg = r'src="(.*?\.+'+imgType+'!slider)" '
imgre = re测试数据pile(reg)
imgList = re.findall(imgre, html)
x=0
for imgurl in imgList:
print imgurl
urllib.urlretrieve(imgurl, '%s.%s' % (x, imgType))
x =x+1


html= getHTML("http://HdhCmsTestgxlcms测试数据")

getImg(html,'jpg')

查看更多关于python抓取网页中的图片示例的详细内容...

  阅读:49次