Beutifulsoap 获取链接 a 文本内容
Python 2022/4/13 10:50:54 点击:不统计
Beutifulsoap 获取链接 a 文本内容
response = requests.get(url, [])
response.encoding = 'utf-8'
soup = BeautifulSoup(response.text, "html5lib")
# 选取 类名为title 的连接,"class" 可以替换为属性名
forasp_obj_array = soup.find_all('a', _class="title")
# 获取BeautifulSoup 的第一个
item = forasp_obj_array[0]
# 获取属性连接地址
url = item.get("href")
print(url)
# 获取连接内所有的文字内容
title = item.get_text()
print(title)