从sql表下载图像并存储在文件夹中

时间:2019-05-27 09:03:08

标签: sql python-3.x image url

我有pageurl的列表,并且该pageurls存储在某个变量中。现在我想下载所有图像并希望存储在我的系统文件夹中。

import pymysql.connections
from urllib.parse import urlparse
conn = pymysql.Connect(host='127.0.0.1', user='root', passwd='', db='anystore_app')
records = "SELECT * FROM amazon_giftcards_mobile_products"
cursor = conn.cursor()
cursor.execute(records)
rec=cursor.fetchall()
for record in rec:
    id= record[1]
    #print(id)
    producturl= record[2]
    #print("product url are:",producturl)
    for urls in producturl.split('.jpg'):
        p1 = urlparse(urls, 'https://')
        netloc = p1.netloc
        path = p1.path if p1.netloc else ''
        if not netloc.startswith('amazon.in/'):
            netloc = 'https://amazon.in' + urls
            p2 = urlparse('.jpg', netloc, path)
            data=(p2.geturl())

0 个答案:

没有答案