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
#5
Hello S,

so all my html files have to be UTF-8

The files are just saved from a word document as Web Page html.


I will do some testing

thanks for the help

Hello S,

I have been testing on the html files you gave.

There is no error with them.

So I have to encode all my html files as UTF-8

The final part to save my images - I get an error

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.save(path+image["src"], "png")
            print(image)
im = Image.open(os.path.join(root, image["src"]))
TypeError: string indices must be integers

My file paths are ok the code looks ok but this error - i dont know

This is the html
<!DOCTYPE html>
<html>
  <body>
    <h2>HTML Image</h2>
    <img src="images/image002.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,654 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,381 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,285 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,846 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