# html_doc can read from file or url soup = BeautifulSoup(html_doc, features='lxml') print(" ".join([img['alt'] for img in soup.find_all('img', alt=True)]))