Python Forum
HTML - Save Images From Folder - PIL
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTML - Save Images From Folder - PIL
#1
Hello,

good sunday all

I have found this code on so that saves images from html files - from a folder.

I keep getting an error

soup = bs(open(os.path.join(root, f)).read())
File "C:\Python\Python36-32\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 254: character maps to <undefined>


import os, os.path
from PIL import Image
from bs4 import BeautifulSoup as bs

path = 'c:/Users/Dan/Desktop/c'

for root, dirs, files in os.walk(path):
    for f in files:
      soup = bs(open(os.path.join(root, f)).read())
      for image in soup.findAll("img"):
        print ("Image: %(src)s" % image)
        im = Image.open(image)
        im.save(path+image["src"], "png")

#https://stackoverflow.com/questions/9610728/how-do-i-extract-images-from-html-files-in-a-directory
I have researched for days - and cant work out what it wants

please will some one be kind enough to advise this error issue

I appreciate your help



:)


Python newbie trying to learn the ropes
Reply


Messages In This Thread
HTML - Save Images From Folder - PIL - by dj99 - Jul-15-2018, 10:55 AM
RE: HTML - Save Images From Folder - PIL - by dj99 - Jul-15-2018, 03:12 PM
RE: HTML - Save Images From Folder - PIL - by dj99 - Jul-15-2018, 05:45 PM
RE: HTML - Save Images From Folder - PIL - by dj99 - Jul-17-2018, 07:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  HTML multi select HTML listbox with Flask/Python rfeyer 0 4,529 Mar-14-2021, 12:23 PM
Last Post: rfeyer
  cant access root environment folder from django folder using __init__.py Sanjish 0 1,874 Dec-25-2020, 05:56 AM
Last Post: Sanjish
  Python3 + BeautifulSoup4 + lxml (HTML -> CSV) - How to loop to next HTML/new CSV Row BrandonKastning 0 2,328 Mar-22-2020, 06:10 AM
Last Post: BrandonKastning
  flask app to save images locally when deployed on heroku not working Prince_Bhatia 1 5,229 Feb-20-2019, 11:59 PM
Last Post: snippsat
  how i save the html form to flask database mebaysan 1 7,244 Feb-07-2019, 12:56 AM
Last Post: snippsat
  Execute using Html, Save data into Database and Download in CSV in Django --Part 1 Prince_Bhatia 0 3,799 Jan-19-2018, 06:05 AM
Last Post: Prince_Bhatia

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020