网站制作学习网Python→正文:Beutifulsoap 获取链接 a 文本内容
字体:

Beutifulsoap 获取链接 a 文本内容

Python 2022/4/13 10:50:54  点击:不统计

学习www.网for站asp制.cn作
 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)
 

·上一篇:python 多线程 并发 >>    ·下一篇:execjs._exceptions.ProgramError: Error: Cannot find module 'jsdom' >>
推荐文章
最新文章