Python + BeautifulSoup: How to get ‘href’ attribute of ‘a’ element?

后端 未结 4 1178
梦如初夏
梦如初夏 2020-12-16 15:21

I have the following:

  html =
  \'\'\'
      
4条回答
  •  执念已碎
    2020-12-16 16:05

    You could solve this with just a couple lines of gazpacho:

    
    from gazpacho import Soup
    
    html = """\
    
    """
    
    soup = Soup(html)
    soup.find("a", {"class": "file-link"}).attrs['href']
    

    Which would output:

    '/file-one/additional'
    

提交回复
热议问题