草庐IT

beautifulsoup4

全部标签

BeautifulSoup文档2-详细方法 | 对象的种类有哪些?

(2-详细方法|对象的种类有哪些?)1使用细节将一段文档传入BeautifulSoup的构造方法,就能得到一个文档的对象,;可以传入一段字符串或一个文件句柄,比如:frombs4importBeautifulSoupsoup=BeautifulSoup(open("index.html"))soup=BeautifulSoup("data")2对象的种类2.1种类说明BeautifulSoup将HTML文档转换成一个树形结构,每个节点都是Python对象;所有对象为4种:Tag,NavigableString,BeautifulSoup,Comment.2.2Tag对象与XML或HTML原生文

BeautifulSoup文档3-详细方法 | 如何对文档树进行遍历?

(3-详细方法|如何对文档树进行遍历?)以下实例还是官网的例子:html_doc="""TheDormouse'sstoryTheDormouse'sstoryOnceuponatimetherewerethreelittlesisters;andtheirnameswereElsie,LacieandTillie;andtheylivedatthebottomofawell...."""frombs4importBeautifulSoupsoup=BeautifulSoup(html_doc,'html.parser')1子节点1.1tag的名字1.1.1获取head标签#获取headpri

BeautifulSoup文档3-详细方法 | 如何对文档树进行遍历?

(3-详细方法|如何对文档树进行遍历?)以下实例还是官网的例子:html_doc="""TheDormouse'sstoryTheDormouse'sstoryOnceuponatimetherewerethreelittlesisters;andtheirnameswereElsie,LacieandTillie;andtheylivedatthebottomofawell...."""frombs4importBeautifulSoupsoup=BeautifulSoup(html_doc,'html.parser')1子节点1.1tag的名字1.1.1获取head标签#获取headpri