728x90
Sample HTML
html_str = '''
<html>
<body>
<img src="path1" alt="테스트 이미지_1" />
<img src="path2" alt="테스트 이미지_2" />
<img src="path3" alt="테스트 이미지_3" />
</body>
</html>
'''
bs_obj = BeautifulSoup(html_str,'html.parser')
find : 첫 번째 태그를 리턴
from bs4 import BeautifulSoup
imgtag = bs_obj.find('img')
print(imgtag['alt'])
---------------------------------------------------
테스트 이미지_1
findAll : 조건에 해당되는 모든 태그를 리스트로 리턴
from bs4 import BeautifulSoup
imgtag = bs_obj.findAll('img')
for tag in imgtag:
print(tag['alt'])
---------------------------------------------------------
테스트 이미지_1
테스트 이미지_2
테스트 이미지_3
728x90