<html> <body> <div id="A"> <source> <img src="画像URL"></img> </source> </div> </body> </html>
この画像URLをimagesに格納するにはどうすればいいんでしょうか?
import requests from bs4 import BeautifulSoup import os url = "" soup = BeautifulSoup(requests.get(url).content,'lxml') div = soup.find("div", id="A") images = div.find_all("img").get("src") for target in images: re = requests.get(target) file_name = 'img/' + target.split('/')[-1] with open(file_name, 'wb') as f: f.write(re.content) print("complete!!") # 確認
回答1件
あなたの回答
tips
プレビュー