当前位置: 首页 > news >正文

繁昌网站建设关键词搜索网站

繁昌网站建设,关键词搜索网站,网站建设 上海,青海省教育厅门户网站https://cuiqingcai.com/5551.html Table of Contents https://cuiqingcai.com/5551.html 基本CSS选择器 查找节点 find() 查找子孙节点 children() 查找子节点 parent() 查找父节点 siblings() 兄弟节点 遍历 单个节点可以直接打印输出 多个节点需要调用items()方…

https://cuiqingcai.com/5551.html

Table of Contents

https://cuiqingcai.com/5551.html

基本CSS选择器

查找节点

find() 查找子孙节点

children() 查找子节点

parent() 查找父节点

siblings()  兄弟节点

遍历

单个节点可以直接打印输出

多个节点需要调用items()方法

获取信息

获取属性: 调用 attr() 方法获取属性 或 attr 属性获取

获取文本: text() 获取节点内所有文本信息  html() 获取第一个节点内的html信息

节点操作

addClass 和   removeClass

attr、text 和   html

remove() 移除

伪类选择器


基本CSS选择器

html = '''
<div id="container"><ul class="list"><li class="item-0">first item</li><li class="item-1"><a href="link2.html">second item</a></li><li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li><li class="item-1 active"><a href="link4.html">fourth item</a></li><li class="item-0"><a href="link5.html">fifth item</a></li></ul></div>
'''
from pyquery import PyQuery as pq
doc = pq(html)print(doc('#container .list a'))
print(doc('.list span'))
print(doc('.bold'))# <a href="link2.html">second item</a><a href="link3.html"><span class="bold">third item</span></a><a href="link4.html">fourth item</a><a href="link5.html">fifth item</a>
# <span class="bold">third item</span>
# <span class="bold">third item</span>

查找节点

find() 查找子孙节点

children() 查找子节点

parent() 查找父节点

siblings()  兄弟节点


html = '''
<div id="container"><ul class="list"><li class="item-0">first item</li><li class="item-1"><a href="link2.html">second item</a></li><li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li><li class="item-1 active"><a href="link4.html">fourth item</a></li><li class="item-0"><a href="link5.html">fifth item</a></li></ul></div>
'''
from pyquery import PyQuery as pq
doc = pq(html)# 子孙节点
print(doc('.list').find('.active'))# 子节点
print(doc('#container').children('.active'))# 子节点
print(doc('.list').children('.active'))# 父节点
print(doc('.bold').parent())# 兄弟节点
print(doc('.item-0.active').siblings())

遍历

单个节点可以直接打印输出

多个节点需要调用items()方法


html = '''
<div id="container"><ul class="list"><li class="item-0">first item</li><li class="item-1"><a href="link2.html">second item</a></li><li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li><li class="item-1 active"><a href="link4.html">fourth item</a></li><li class="item-0"><a href="link5.html">fifth item</a></li></ul></div>
'''
from pyquery import PyQuery as pq
doc = pq(html)# 单个节点
li = doc('.item-0.active')
print(li)
print(str(li))# 多个节点
print('*'*20)
lis = doc('li').items()
for i in lis:print(i)

获取信息

获取属性: 调用 attr() 方法获取属性 或 attr 属性获取

获取文本: text() 获取节点内所有文本信息  html() 获取第一个节点内的html信息


html = '''
<div id="container"><ul class="list"><li class="item-0">first item</li><li class="item-1"><a href="link2.html">second item</a></li><li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li><li class="item-1 active"><a href="link4.html">fourth item</a></li><li class="item-0"><a href="link5.html">fifth item</a></li></ul></div>
'''
from pyquery import PyQuery as pq
doc = pq(html)# attr方法 和 attr属性
a = doc('.item-1.active a')
print(a.attr('href'))
print(a.attr.href)# attr方法 和 attr属性
print(list(doc('div .item-0').items())[2].find('a').attr('href'))
print(list(doc('div .item-0').items())[2].find('a').attr.href)# text() 获取文本
print(doc('.item-1.active a').text())
print(doc('.item-1.active a').html())# 获取第一个 li 的文本
print(doc('li').html())
# 获取所有 li 的文本
print(doc('li').text())

节点操作

addClass 和   removeClass

html = '''
<div class="wrap"><div id="container"><ul class="list"><li class="item-0">first item</li><li class="item-1"><a href="link2.html">second item</a></li><li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li><li class="item-1 active"><a href="link4.html">fourth item</a></li><li class="item-0"><a href="link5.html">fifth item</a></li></ul></div></div>
'''
from pyquery import PyQuery as pq
doc = pq(html)li = doc('.item-0.active')
print(li)# 移除 class
li.removeClass('active')
print(li)# 添加 class
li.addClass('test')
print(li)

attrtext 和   html

html = '''
<ul class="list"><li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li>
</ul>
'''
from pyquery import PyQuery as pq
doc = pq(html)li = doc('.item-0.active')
print(li)# 添加 name
li.attr('name', 'link')
print(li)# 修改 text 纯文本
li.text('changed item')
print(li)# 修改 html 文本
li.html('<span>changed item</span>')
print(li)

remove() 移除

html = '''
<div class="wrap">Hello, World<p>This is a paragraph.</p></div>
'''
from pyquery import PyQuery as pq
doc = pq(html)
wrap = doc('.wrap')
print(wrap.text())wrap.find('p').remove()
print(wrap)
print(wrap.text())

伪类选择器

http://www.w3school.com.cn/css/index.asp

html = '''
<div class="wrap"><div id="container"><ul class="list"><li class="item-0">first item</li><li class="item-1"><a href="link2.html">second item</a></li><li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li><li class="item-1 active"><a href="link4.html">fourth item</a></li><li class="item-0"><a href="link5.html">fifth item</a></li></ul></div></div>
'''
from pyquery import PyQuery as pq
doc = pq(html)
li = doc('li:first-child')
print(li)
li = doc('li:last-child')
print(li)
li = doc('li:nth-child(2)')
print(li)
li = doc('li:gt(2)')
print(li)
li = doc('li:nth-child(2n)')
print(li)

 

http://www.lbrq.cn/news/2742733.html

相关文章:

  • html网站开发心得体会常用的关键词挖掘工具
  • 宝安网站开发企业营销管理
  • 南宁有名的网络公司拼多多seo怎么优化
  • 网站编程论文好搜网
  • 36氪国外做网站苏州seo网站推广哪家好
  • 用h5做的网站广州搜发网络科技有限公司
  • 广西建筑八大员报考官网重庆seo网络推广关键词
  • 室内设计设计师网站推荐物联网开发
  • 建筑工程公司有哪些岗位重庆百度推广seo
  • 怎么做网站的内链外链软文范例大全100字
  • 手机网站商城建设答辩推广普通话宣传海报
  • 谁有做网站比较厉害的电商具体是做什么的
  • 算命先生的网站怎么做网店推广方案
  • 网站建设图片代码广告公司收费价格表
  • 百度怎么推广产品盐城seo营销
  • 绿色能源网站模板seo软件下载
  • 百度怎么建立网站苏州搜索引擎排名优化商家
  • 青岛哪里做网站遵义网站seo
  • 公司网站开发排名长春seo排名公司
  • word 关于做网站长沙网站推广公司
  • 网站建设方案2018郑州优化网站公司
  • 上海松江区做网站的公司排名函数
  • 投票活动网站怎么做高端网站建设的公司
  • 大同网站建设设计毕业设计网站
  • 网站建设资讯版块如何做用户运营查数据的网站有哪些
  • 网站的基础知识电子商务网店运营推广
  • 网站建设功能规划个人免费开发网站
  • 移动端网站开发流程图网页制作代码模板
  • 做公司网站需要什么程序百度云官方网站
  • 南京师范大学课程建设网站天津百度推广电话号码
  • 攻防世界—unseping(反序列化)
  • 官方正版在线安装office 365安装工具
  • 开发者说 | EmbodiedGen:为具身智能打造可交互3D世界生成引擎
  • 写一个linux脚本,要求实现查找9010端口,如果端口存在则kill,否则不处理,返回对应的提示
  • springboot集成websocket
  • 【Java web】HTTP 协议详解