要使用BeautifulSoup库从HTML文本中提取包含"https"的链接,您可以按照以下步骤操作:
beautifulsoup4
和lxml
这两个库。如果没有,请使用以下命令进行安装:pip install beautifulsoup4 lxml
from bs4 import BeautifulSoup
html_text = '''<html>
<body>
<a href="https://www.example.com">Example</a>
<a href="http://www.example.com">Example</a>
<a href="https://www.example2.com">Example2</a>
</body>
</html>'''
soup = BeautifulSoup(html_text, 'lxml')
https_links = soup.find_all('a', href=re.compile(r'https'))
for link in https_links:
print(link['href'])
这将输出以下结果:
https://www.example.com
https://www.example2.com
腾讯金融云
北极星训练营
北极星训练营
北极星训练营
北极星训练营
开箱吧腾讯云
微服务平台TSF系列直播
云原生正发声
中国航空运输协会安保培训
中国航空运输协会安保培训
中国航空运输协会安保培训
中国航空运输协会安保培训
领取专属 10元无门槛券
手把手带您无忧上云