当前位置 博文首页 > python抓取网页中的图片示例

    python抓取网页中的图片示例

    作者:admin 时间:2021-06-27 18:29

    复制代码 代码如下:

    #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("http://blog.iis7.com")

    getImg(html,'jpg')

    js
    下一篇:没有了