简单的python爬虫图片获取

2021-06-08 03:04

阅读:392

标签:read   find   code   open   utf-8   port   pen   page   main   

# 图片爬取

import re
import urllib
import urllib.request

def gethtml(url):
    page=urllib.request.urlopen(url)  
    html=page.read() 
    return html

def getimg(html):
    reg = rsrc="http://www.soscw.com/(.*?\.jpg)"
    img=re.compile(reg)
    html=html.decode(utf-8) 
    imglist=re.findall(img,html)  
    x = 0
    for imgurl in imglist:
        urllib.request.urlretrieve(imgurl,D:\\迅雷下载\\%s.jpg%x)
        x = x+1    
if __name__ == "__main__":
    html=gethtml("http://pic.yxdown.com/list/0_0_1.html")#图片地址链接
    getimg(html)

 

简单的python爬虫图片获取

标签:read   find   code   open   utf-8   port   pen   page   main   

原文地址:https://www.cnblogs.com/Outsider07/p/14537663.html


评论


亲,登录后才可以留言!