PyQuery 文档标注
来源:互联网 发布:淘宝寄到海外 编辑:程序博客网 时间:2024/06/05 00:22
官方文档
PyQuery complete API
用来筛选
- PyQuery.eq(index)[source]
>>> d = PyQuery('<p class="hello">Hi</p><p>Bye</p><div></div>')>>> d('p').eq(0)[<p.hello>]>>> d('p').eq(1)[<p>]>>> d('p').eq(2)[]
- PyQuery.find(selector)[source]
>>> m = '<p><span><em>Whoah!</em></span></p><p><em> there</em></p>'>>> d = PyQuery(m)>>> d('p').find('em')[<em>, <em>]>>> d('p').eq(1).find('em')[<em>]
- PyQuery.filter(selector)[source]
>>> d = PyQuery('<p class="hello">Hi</p><p>Bye</p>')>>> d('p')[<p.hello>, <p>]>>> d('p').filter('.hello')[<p.hello>]>>> d('p').filter(lambda i: i == 1)[<p>]>>> d('p').filter(lambda i: PyQuery(this).text() == 'Hi')[<p.hello>]>>> d('p').filter(lambda i, this: PyQuery(this).text() == 'Hi')[<p.hello>]
- PyQuery.items(selector=None)[source]
>>> d = PyQuery('<div><span>foo</span><span>bar</span></div>')>>> [i.text() for i in d.items('span')]['foo', 'bar']>>> [i.text() for i in d('span').items()]['foo', 'bar']
用来上下查找
- PyQuery.children(selector=None)[source]
>>> d = PyQuery('<span><p class="hello">Hi</p><p>Bye</p></span>')>>> d[<span>]>>> d.children()[<p.hello>, <p>]>>> d.children('.hello')[<p.hello>]
- PyQuery.parents(selector=None)
>>> d = PyQuery('<span><p class="hello">Hi</p><p>Bye</p></span>')>>> d('p').parents()[<span>]>>> d('.hello').parents('span')[<span>]>>> d('.hello').parents('p')[]
- PyQuery.closest(selector=None)[source]
>>> d = PyQuery(... '<div class="hello"><p>This is a '... '<strong class="hello">test</strong></p></div>')>>> d('strong').closest('div')[<div.hello>]>>> d('strong').closest('.hello')[<strong.hello>]>>> d('strong').closest('form')[]
- PyQuery.end()[source]
>>> m = '<p><span><em>Whoah!</em></span></p><p><em> there</em></p>'>>> d = PyQuery(m)>>> d('p').eq(1).find('em').end().end()[<p>, <p>]
- PyQuery.nextAll(selector=None)[source]
>>> h = '<span><p class="hello">Hi</p><p>Bye</p><img scr=""/></span>'>>> d = PyQuery(h)>>> d('p:last').nextAll()[<img>]# 注意这里的:last,用来选择最后一个匹配
- PyQuery.prevAll(selector=None)[source]
>>> h = '<span><p class="hello">Hi</p><p>Bye</p><img scr=""/></span>'>>> d = PyQuery(h)>>> d('p:last').prevAll()[<p.hello>]
- PyQuery.outerHtml()[source]
>>> d = PyQuery('<div><span class="red">toto</span> rocks</div>')>>> print(d('span'))<span class="red">toto</span> rocks>>> print(d('span').outerHtml())<span class="red">toto</span>>>> S = PyQuery('<p>Only <b>me</b> & myself</p>')>>> print(S('b').outerHtml())<b>me</b># 注意,取span会取到后面的text,outerHtml就只取span
- PyQuery.siblings(selector=None)[source]
>>> h = '<span><p class="hello">Hi</p><p>Bye</p><img scr=""/></span>'>>> d = PyQuery(h)>>> d('.hello').siblings()[<p>, <img>]>>> d('.hello').siblings('img')[<img>]
用来判断
- PyQuery.hasClass(name)[source]
>>> d = PyQuery('<div class="myclass"></div>')>>> d.hasClass('myclass')True
- PyQuery.is_(selector)[source]
>>> d = PyQuery('<p class="hello">Hi</p><p>Bye</p><div></div>')>>> d('p').eq(0).is_('.hello')True>>> d('p').eq(1).is_('.hello')False
- PyQuery.not_(selector)[source]
>>> d = PyQuery('<p class="hello">Hi</p><p>Bye</p><div></div>')>>> d('p').not_('.hello')[<p>]
获取内容
- PyQuery.text(value=)[source]
>>> doc = PyQuery('<div><span>toto</span><span>tata</span></div>')>>> print(doc.text())toto tata
- PyQuery.val(value=)[source]
>>> d.val()'Youhou'
- PyQuery.width(value=)[source]
- PyQuery.height(value=)[source]
注意
使用pyquery的时候,一定要注意namespace,可能找不到element。先移除doc = pq(html).remove_namespaces()
阅读全文
0 0
- PyQuery 文档标注
- pyQuery
- PyQuery
- 给文档做标注
- Selenium 文档标注
- DocTag2Vec, 文档标注
- 高亮标注LaTex文档中的修订
- PyQuery介绍
- pyquery安装
- 安装pyquery
- python pyquery
- pyquery安装
- pyquery小记
- pyquery ----用法
- 五. PyQuery
- 007 PyQuery
- 标注
- 标注
- TabLayout、ViewPager、FragmentPagerAdapter实现新闻导航栏
- 61_数组_多维数组_练习_矩阵运算
- js实现螺旋矩阵算法
- 九度oj-1013-开门人和关门人
- Unique Paths
- PyQuery 文档标注
- hihoCoder1050— 树中的最长路(深搜)
- 6.3 有限字长效应
- tomcat 使用log4j做日志分隔
- 1059. C语言竞赛(20) PAT
- 数学游戏“数三角形”的可编程图论模型
- VC6.0期末实践项目药品信息管理系统
- 图片水印(张高伟)
- Vuforia的ImagetTarget的扫描图无法正常显示