如何使用Python打印html文件中的特定标记?

如何使用Python打印html文件中的特定标记?,python,html,python-2.7,python-3.x,tags,Python,Html,Python 2.7,Python 3.x,Tags,如何使用Python打印所有html文件?使用或。这两种方法中的任何一种都应该能够帮助您完成所需的工作,具体取决于您是否希望实际包含标记。使用库 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

如何使用Python打印所有
html文件?

使用或。这两种方法中的任何一种都应该能够帮助您完成所需的工作,具体取决于您是否希望实际包含标记。

使用库

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