BeatifuleSoup(response.text,‘html.parser‘)里面的数据结构

本文详细介绍了使用BeautifulSoup解析HTML时,`soup=BeautifulSoup(response.text,'html.parser')`和`soup.find_all()`返回的数据结构。内容包括节点的概念、不同类型节点的属性和文本,以及如何通过find_all()进行数据查询,包括正则表达式的应用。同时,讲解了如何通过节点索引和方法访问子节点、属性和文本。" 16951651,1376248,cocos2d-X UIInputManager.h API详解,"['cocos2d-x', '游戏开发', 'API接口']
摘要由CSDN通过智能技术生成

1.主要内容

soup=BeatifuleSoup(response.text,'html.parser') , soup的数据结构

find=soup.find_all(),find的数据结构

1.代码

在python IDE 运行结果

>>> import requests
>>> from bs4 import BeautifulSoup
>>> res=requests.get('https://www.baidu.com/')
>>> res.encoding='utf-8'
>>> soup=BeautifulSoup(res.text,'html.parser')
>>> type(soup)
<class 'bs4.BeautifulSoup'>

>>> print(soup)
<!DOCTYPE html>

<!--STATUS OK--><html> <head><meta content="text/html;charset=utf-8" http-equiv="content-type"/>…………………………………………………………</html>

>>>find=soup.find_all('a')

>>>type(find)
<class 'bs4.element.ResultSet'>

print(find)
[<a class="mnav" href="h

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值