これはこの質問のフォローアップです:How do I parse every html file in a directory for images? 本質的に、私はそれぞれが同じディレクトリに別々に保存したい画像を含むhtmlファイルのディレクトリを持っています。ディレクトリ内のhtmlファイルからイメージを抽出するにはどうすればよいですか?
プログラムに提案された変更を行った後、私はまだエラーを取得しています:
Image: theme/pfeil_grau.gif
Traceback (most recent call last):
File "C:\Users\gokalraina\Desktop\modfile.py", line 25, in <module>
im = Image.open(image)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1956, in open
prefix = fp.read(16)
TypeError: 'NoneType' object is not callable
これは、私が使用しています改訂コード(nightcrackerのおかげで)です。
import os, os.path
import Image
from BeautifulSoup import BeautifulSoup as bs
path = 'C:\Users\gokalraina\Desktop\derm images'
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"], "JPEG")
'印刷のための1つを含む、それまでの全体の出力を、明記してください。 –
私はそれを追加しました。それが壊れる前に唯一の印刷物があった。 –