0
我想從使用美麗的湯的文章刮圖像。它似乎工作,但我無法打開圖像。每次嘗試從我的桌面訪問圖像時,都會收到文件格式錯誤。任何見解?使用美麗的湯刮圖像
timestamp = time.asctime()
# Parse HTML of article, aka making soup
soup = BeautifulSoup(urllib2.urlopen(url).read())
# Create a new file to write content to
txt = open('%s.jpg' % timestamp, "wb")
# Scrape article main img
links = soup.find('figure').find_all('img', src=True)
for link in links:
link = link["src"].split("src=")[-1]
download_img = urllib2.urlopen(link)
txt.write('\n' + "Image(s): " + download_img.read() + '\n' + '\n')
txt.close()