繁体   English   中英

如何使用Python从html文件中打印特定标签? [重复]

[英]How can I print specific tags from a html file with Python? [duplicate]

如何使用Python打印 html文件中的所有<a>标记?

使用beautifulsoup库。

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

使用reBeautiful Soup 这两种方法中的任何一种都应能够帮助您满足您的需要,这取决于您是否实际要包含标签。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM