使用 find_all() 方法替代 find() 方法,并使用 for 循环遍历所有结果。
示例代码:
html_doc = """
The Dormouse's story
Once upon a time there were three little sisters; and their names were Elsie, Lacie and Tillie; and they lived at the bottom of a well.
...
"""from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc, 'html.parser')
links = soup.find_all('a')
for link in links: print(link.get('href')) # 输出链接地址