beautifulsoup 4 使用

官方文档

https://beautifulsoup.readthedocs.io/zh_CN/v4.4.0/

 

使用case:

soup.find_all('a')
# [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>,
#  <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>,
#  <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]

从文档中找到所有<a>标签的链接:

for link in soup.find_all('a'):
    print(link.get('href'))
    # http://example.com/elsie
    # http://example.com/lacie
    # http://example.com/tillie

 

doing

posted @ 2021-12-20 15:03  年华似水゛  阅读(36)  评论(0)    收藏  举报