可以使用BeautifulSoup的find()或find_all()方法结合属性选择器来获取包含href属性的a标签元素,并使用get()方法获取其href属性值。例如,以下代码可以获取上述HTML代码中的href属性值:
```python
from bs4 import BeautifulSoup
html = '
第2章 李肇获封'
soup = BeautifulSoup(html, 'html.parser')
link = soup.find('a', href=True)
href = link.get('href')
print(href)
```
输出结果为:`/book/144498/2.html`
在这个例子中,我们使用了find()方法和属性选择器'a[href]'来获取包含href属性的a标签元素,并使用get()方法获取其href属性值。如果有多个符合条件的元素,可以使用find_all()方法来获取所有元素,并遍历它们来获取href属性值。