执行代码:
import bs4
import requests
url = 'https://so.gushiwen.org/authors/authorvsw_b90660e3e492A1.aspx'
headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
html = requests.get(url,headers=headers).text#.content.decode('utf-8')
soup = bs4.BeautifulSoup(html, "lxml")
a=soup.find("body",{"onclick":"closeshowBos()"}).find("div",{"class":"main3"}).find("div",{"class":"left"}).find("div",{"class":"sons"}).find("div",{"class":"cont"}).find("p").find("a",{"target":"_blank"}).find("b").text
print('a=',a)
b=soup.find("p").find("b").text #可省略不必要部分~~~~p~~~b
print('b=',b)
运行结果: