Python PyQuery 库基础
初始化
字符串初始化
1 | !pip install pyquery |
URL初始化
1 | from pyquery import PyQuery as pq |
文件初始化
1 | from pyquery import PyQuery as pq |
基本CSS选择器
1 | html = ''' |
查找元素
子元素
1 | html = ''' |
children
1 | lis = items.children() |
- 返回items孩子节点中class为active为标签
1 | lis = items.children('') |
父元素
1 | html = ''' |
parent
1 | Pythonhtml = ''' |
- 查找返回items祖先节点里class为wrap的祖先标签
1 | parent = items('.wrap') |
兄弟元素
1 | html = ''' |
1 | html = ''' |
遍历
单个元素
1 | html = ''' |
1 | html = ''' |
获取信息
获取属性
1 | html = ''' |
获取文本
1 | html = ''' |
获取 HTML
1 | html = ''' |
DOM 操作
addClass、removeClass
1 | html = ''' |
attr、css
1 | html = ''' |
remove
1 | html = ''' |
伪类选择器
1 | html = ''' |