当前位置: 移动技术网 > IT编程>脚本编程>Python > python抓取网页中的图片示例

python抓取网页中的图片示例

2019年04月01日  | 移动技术网IT编程  | 我要评论

强强论坛,监利县吧,盘龙血族

复制代码 代码如下:

#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.compile(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("//www.jb51.net")

getimg(html,'jpg')

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网