我从不同的sql表中获取了imageurl并从那里下载图像,并将该图像存储在我的系统中。现在,我要将文件夹路径存储在其他sql表中。
import pymysql.connections
from urllib.request import urlretrieve
try:
conn = pymysql.connect(host='127.0.0.1', user='root', passwd='', db='anystore_app')
cur = conn.cursor()
sql_select_Query="SELECT * FROM amazon_beauty_health_gorcery_images"
cursor = conn.cursor()
cursor.execute(sql_select_Query)
records = cursor.fetchall()
for row in records:
id= row[0]
image_extension= 'JPG'
product_id= row[3]
print(product_id)
imageurl= row[1]
#print(imageurl)
if imageurl=="":
print("Image Not Available")
else:
urlretrieve(imageurl,"D:/upload/products/product_id_{}.jpg".format(product_id))
cursor.execute("INSERT INTO anystore_masterdb.new_table(product_id,image_extension,imageurl)"
" VALUES(%s,%s,%s)",(product_id, image_extension,imageurl))
conn.commit()
cursor.close()
except Exception as e:
print("Error:-", e)