获取图片和下载到本地和名字和链接的获取

Posted 你若精彩,蝴蝶自来

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取图片和下载到本地和名字和链接的获取相关的知识,希望对你有一定的参考价值。

# -*- coding: utf-8 -*-
import urllib.request
import ssl
import json
import xlwt
context = ssl._create_unverified_context()

title=[女装,鞋包,男士,运动,饰品,美妆,母婴,居家,国际,生活]
wb = xlwt.Workbook()
class spider:
    def url_name(self):
        wb = xlwt.Workbook()
        for i in range(len(title)):
            list_name = []
            list_img = []
            print(i+1)
            ws = wb.add_sheet(title[i])
            url = http://www.vip.com/index-ajax.php?act=getSellingBrandListV5&warehouse=VIP_NH&areaCode=104104&channelId=0&pagecode=b&sortType=1&province_name=%E5%B9%BF%E4%B8%9C&city_name=%E5%B9%BF%E5%B7%9E%E5%B8%82&preview=&sell_time_from=&time_from=&ids=+str(i+1)
            url_data = urllib.request.urlopen(url).read().decode("utf-8")
            print(url_data)
            jsDict = json.loads(url_data)
            print(jsDict)
            jsdata = jsDict[data]
            jsfloor = jsdata[floors]
            jsfirst = jsfloor[str(i+1)]
            jsitems = jsfirst[items]
            for each in jsitems:
                list_img.append(each[mobile_image_one])
                list_name.append(each[name])
            print(len(list_img))
            print(len(list_name))
            print(list_name)
            print(list_img)
            for each in range(len(list_name)):
                ws.write(each, 0, list_name[each])
                ws.write(each, 1, list_img[each])
            x=0
            for j in list_img:
                urllib.request.urlretrieve(j, D:\\weipinhui\\monning_1\\jingxuan_pic\\+str(i+1)+\\%s.jpg % x)
                x = x + 1
            wb.save(D:\\weipinhui\\monning_1\\jingxuan_name_url\\jingxuan_name_url.xls)
    def shouye(self):
        wb = xlwt.Workbook()
        ws = wb.add_sheet(首页)
        list_name_sy=[]
        list_img_sy=[]
        url = http://pcapi.vip.com/ads/index.php?callback=shopAds&type=ADSEC56K%2CADSIR7IX%2CADSX7W3G%2CADSNNLS7%2CADS7JI3F%2CADS2B669%2CADSITG64%2CADS45AV4%2CADS44T33&warehouse=VIP_NH&areaid=104104&preview=0&date_from=&time_from=&user_class=&channelId=0
        url_data = urllib.request.urlopen(url).read().decode("utf-8")
        url_data = url_data.replace(shopAds(, ‘‘)
        url_data = url_data.replace(), ‘‘)
        jsDict = json.loads(url_data)
        print(jsDict)
        jsdata = jsDict[ADADSEC56K]
        jsdatas = jsdata[items]
        for each in jsdatas:
            list_name_sy.append(each[name])
            list_img_sy.append(each[img])
        print(list_img_sy)
        print(list_name_sy)
        x = 0
        for each in range(len(list_name_sy)):
            ws.write(each, 0, list_name_sy[each])
            ws.write(each, 1, list_img_sy[each])
        for j in list_img_sy:
            urllib.request.urlretrieve(j, D:\\weipinhui\\monning_1\\shouye_pic\\%s.jpg % x)
            x = x + 1
        wb.save(D:\\weipinhui\\monning_1\\shouye_name_url\\shouye_name_url.xls)
content=spider()
content.url_name()
content.shouye()

 

以上是关于获取图片和下载到本地和名字和链接的获取的主要内容,如果未能解决你的问题,请参考以下文章

根据图片的url地址下载图片到本地保存代码片段

js 获取图片并下载到本地

android怎么获取刚刚下载安装的APK的APP名字和图片

PHP——下载图片到本地代码

小程序各种功能代码片段整理---持续更新

php自动下载远程文件问题