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
#7
Hello s,


when i use this line to check the path

print(os.path.join(root, image))

i get the correct path
eg

c:/Users/Dan/Desktop/a/images/image001.jpg


When I use it in the complete code.

The image does not get saved




import os, os.path
from PIL import Image
from bs4 import BeautifulSoup as bs
 
path = 'c:/Users/Dan/Desktop/a/'
for root, dirs, files in os.walk(path):
    for f in files:
        soup = bs(open(os.path.join(root, f)), 'lxml')
        
        for image in soup.find_all("img"):
            image = image.get('src')

            
            #im = Image.open(os.path.join(root, image["src"]))
            
            im = Image.open(os.path.join(root, image))    #["src"]))

            im.save(path+image, "png")   # < < < Image not saving


	    # print(os.path.join(root, image))
Unicode error
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 77: character maps to <undefined>

using the html file below
<!DOCTYPE html>
<html>
  <body>
    <h2>HTML Image</h2>
    <img src="images/image001.jpg" alt="Flowers in Chania" width="460" height="345">
  </body>
</html>



:)


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,653 Mar-14-2021, 12:23 PM
Last Post: rfeyer
  cant access root environment folder from django folder using __init__.py Sanjish 0 1,919 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,379 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,280 Feb-20-2019, 11:59 PM
Last Post: snippsat
  how i save the html form to flask database mebaysan 1 7,314 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,845 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