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

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

I have the following:

  html =
  \'\'\'
      
4条回答
  •  粉色の甜心
    2020-12-16 16:24

    You can also use attrs to get the href tag with regex search

    soup.find('a', href = re.compile(r'[/]([a-z]|[A-Z])\w+')).attrs['href']
    

提交回复
热议问题