Saya mencoba mengunduh semua gambar dari situs web tetapi tidak dapat melakukannya. Bagaimana saya bisa mengunduh semua gambar dari bagian tertentu di situs web dan menyimpannya ke direktori saya?
Kode di bawah ini mengekspor semua gambar dan menyimpan tautan gambar ke file csv, tetapi saya juga ingin gambar tersebut menyimpannya di direktori saya juga.
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup as soup
my_url = 'https://www.newegg.com/Video-Cards-Video-Devices/Category/ID-38?Tpk=graphics%20card'
req = Request(my_url, headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req).read()
page_soup = soup(webpage, "html.parser")
filename = "abc.csv"
f = open(filename, "w")
headers = "imagelink\n"
f.write(headers)
snackcrisps = page_soup.findAll("div",{"class":"divCategories divShops-newegg"})
crispitem = snackcrisps[0]
img = crispitem.findAll("div",{"class":"product_image_div productSmall_image_div_lit"})
img1 = img[0]
for img1 in img:
img2 = img1.findAll('img')
imageLink = img2[0].get('src')
print("imageLink: " + imageLink)
f.write(imageLink + "\n")
f.close()
Bagaimana cara menyimpan gambar di direktori lokal saya? Dibutuhkan bantuan!!
Terimakasih banyak