pip install beautifulsoup4
from bs4 import BeautifulSoup
...
response = requests.get(url, headers={'User-Agent':random.choice(userAgent)})
"""
<div class="sonspic">
<div class="cont" style="margin-top:13px;">
<p style="height:22px;">
<a target="_blank" style="font-size:18px; line-height:22px; height:22px;" href="/xxx/book_46653FD803893E4F93E5C6C3.aspx"><b>尚书</b></a>
</p>
</div>
</div>
"""
soup = BeautifulSoup(response.text, 'html.parser')
st = soup.find_all(attrs={"class": "sonspic"})
for i in st:
text = i.select('a')[0].get_text()
# "尚书"
url = i.select('a')[0].get('href')
# "/xxx/book_46653FD803893E4F93E5C6C3.aspx"
Tag类型可以直接转换为字符串。
st = soup.find_all(attrs={"class": "sonspic"})
print(type(st)) # <class 'bs4.element.Tag'>
print(str(st))