-1

How can I print all the <a> tags in this html file with Python?

0

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.