python画像クローラを作成したいと思います。imgae srcを取得し、python image crawlerで画像をディレクトリに保存する
これは私が今持っているものです。
from bs4 import BeautifulSoup
from urllib.request import urlopen
url = 'http://blog.pouyacode.net/'
data = urlopen(url)
soup = BeautifulSoup(data, 'html.parser')
img = soup.findAll('img')
print (img)
print ('\n')
print ('****************************')
print ('\n')
for each in img:
print(img.get('src'))
print ('\n')
この部分は動作します:
print (img)
print ('\n')
print ('****************************')
print ('\n')
しかし、出力の*****************
後に、このエラーが表示されます:
Traceback (most recent call last):
File "pull.py", line 15, in <module>
print(img.get('src'))
AttributeError: 'ResultSet' object has no attribute 'get'
だから、どのようにすることができます私はすべての画像のすべてのSRCを取得しますか? これらの画像をディレクトリに保存するにはどうすればよいですか?
をテストしていない代わりに、img.getの(「SRC」)(「SRC」) – Zillolo
はい、申し訳ありませんそれは少し間違いでした!ありがとうございました。しかし、2番目のものはどうですか?フォルダに画像を保存しますか? – niloofar