How can I print all the <a> tags in this html file with Python?
2 Answers
Using beautifulsoup library.
from bs4 import BeautifulSoup
with open('text.html') as input_file:
soup = BeautifulSoup(input_file)
a_links = soup.find_all('a')
for link in a_links:
print link
Comments
Use re or Beautiful Soup. Either of those should be able to help you with what you need depending on whether or not you want to actually include the tags.