May-16-2020, 01:00 PM
Also if have real html and not a mess like this with some href trow in,then should use a parser.
from bs4 import BeautifulSoup html = '''\ <div class='animals'> <a href="https://en.wikipedia.org/wiki/Dog">dog</a> <a href="https://en.wikipedia.org/wiki/Cat">cat</a> </div>''' soup = BeautifulSoup(html, 'lxml') print([tag.text for tag in soup.find_all('a')])
Output:['dog', 'cat']