【原创】Python PyQuery&nbsp…
来源:互联网 发布:卖衣服的淘宝店 编辑:程序博客网 时间:2024/05/29 11:39
新浪微博对标签和文本支持不是很好,所以很多标签文本被当作html标签了,大致意思还是可以懂的
有一段html如下:con = "
P1
>>> pq(con).text()
'P1 B1-Child P-Parent B2-Child P2'
>>> pq(con)[0].text
'P1'
#此处注意:如果要获取父标签的内容,只能获取到父标签第一个子标签之前的内容。
>>> pq("P")[0].text
'P'
>>> pq("P")[0].text
>>> pq("P1 P2")[0].text
'P1'
如果要要获取父标签(不含自标签)所有内容,需要将子标签remove掉。
>>> pq("P1P2").remove('b').text()
'P1 P2'
>>> pq(con).remove('b').text()
'P1 P-Parent P2'
#同理,如果子标签有多个,可以使用逗号','分割
>>> pq(" P1 b a P2").remove('b,a').text()
'P1 P2'
0 0
- 【原创】Python PyQuery&nbsp…
- 【原创】 linux Python&…
- 【原创】python requests&nbs…
- 【原创】python Reuqests&nbs…
- 【原创】python requests&nbs…
- 【原创】please install&nbsp…
- [原创]android resource&nbsp…
- 【原创】sudo: -User-&…
- 【原创】Python 封装-实现&nb…
- 【原创】SSH/Python Error:&n…
- 【原创】 Window 7&nbsp…
- 【转载】 linux Python&…
- 【原创】Linux-Ubuntu 12.04&…
- 【原创】Linux-Ubuntu 12.04&…
- 【原创】 MySQLdb.cursors&nb…
- 【原创】Mysql Waring/Error&…
- 【原创】windows mongodb&nbs…
- 【原创】centos python2.6.6&…
- 【原創】python sqlite3&nbsp…
- 【原創】Linux Shell 查…
- 系统学习深度学习(二十四)--WRN
- 【原創】Linux ubuntu 软件源
- 【原创】sudo: -User-&…
- 【原创】Python PyQuery&nbsp…
- 【原创】linux zip 只压…
- 关于java多线程
- 【原创】python Reuqests&nbs…
- 【原创】centos python2.6.6&…
- 【原创】centos 打开防火墙端…
- huchi's mysql扫盲笔记
- 【原创】 下载 安装 bootstrap
- 【原创】VIM 快捷键大全&nbsp…