beautifulsoup

1、安装

pip install beautifulsoup4

 

2、

from bs4 import BeautifulSoup

 

html = BeautifulSoup(page_source,features='html.parser')
这个parser取决于我们要解析哪种网页,比如xml, lxml, html


3、如何查找元素和标签?

html.find(name=None, attrs={}, recursive=True, text=None,**kwargs):

name是标签名,如a标签,div, script等

attrs可以根据id, class, name 等等进行查找, text是标签里的text

 

并且还有html.findall() find.next(), findparent等

 

posted @ 2020-09-25 14:16  yjy888  阅读(95)  评论(0编辑  收藏  举报