使用BeautifulSoup库的.find方法来获取href信息。示例代码如下:
from bs4 import BeautifulSoup
import requests
# 发送get请求获取网页内容
response = requests.get('https://example.com')
html_content = response.text
# 创建BeautifulSoup对象
soup = BeautifulSoup(html_content, 'html.parser')
# 使用.find方法找到特定标签
a_tag = soup.find('a')
# 获取href属性值
if a_tag is not None:
href = a_tag.get('href')
print(href)
else:
print('没有找到a标签')
这样就可以获取到a标签的href属性值。