import requests from bs4 import BeautifulSoup from base64 import b64decode url = "https://yukicoder.me/problems/no/3107" r = requests.get(url) soup = BeautifulSoup(r.text, 'lxml') imgs = soup.find_all('img') dat = b'' for img in imgs: s = img.get('src') if s.startswith('data:audio/mpeg;base64'): dat = b64decode(s.replace('data:audio/mpeg;base64,', '')) with open('apf.mpg', 'wb') as f: f.write(dat) スクレイピング用コード