美文网首页
python3 爬图片

python3 爬图片

作者: ma8345 | 来源:发表于2018-11-27 16:03 被阅读0次
#coding:utf8
import urllib.request
import re
import os
import urllib

def getHtml(url):
    request = urllib.request.Request(url)
    page = urllib.request.urlopen(request)
    html = page.read()

    return html

def getImg(html):
    reg = r'src="(.+?\.jpg)" pic_ext'
    imgre = re.compile(reg)
    imglist = re.findall(imgre,html.decode("utf-8"))


    x=1
    paths = 'D:\\imgs'

    for imgurl in imglist:
       urllib.request.urlretrieve(imgurl,'{}\\{}.jpg'.format(paths,x))
       x += 1
    return imglist

html = getHtml("")
getImg(html)

相关文章

网友评论

      本文标题:python3 爬图片

      本文链接:https://www.haomeiwen.com/subject/ltqrzftx.html