1、通过标签选择

# 选择所有title标签
soup.select("title")
# 选择所有p标签中的第三个标签
soup.select("p:nth-of-type(3)") 相当于soup.select(p)[2]
# 选择body标签下的所有a标签
soup.select("body a")
# 选择body标签下的直接a子标签
soup.select("body > a")
# 选择id=link1后的所有兄弟节点标签
soup.select("#link1 ~ .mysis")
# 选择id=link1后的下一个兄弟节点标签
soup.select("#link1 + .mysis")

  2、通过类名查找

# 选择a标签,其类属性为mysis的标签
soup.select("a.mysis")

  

  3、通过id查找

# 选择a标签,其id属性为link1的标签
soup.select("a#link1")

  

  4、通过【属性】查找,当然也适用于class

# 选择a标签,其属性中存在myname的所有标签
soup.select("a[myname]")
# 选择a标签,其属性href=http://example.com/lacie的所有标签
soup.select("a[href='http://example.com/lacie']")
# 选择a标签,其href属性以http开头
soup.select('a[href^="http"]')
# 选择a标签,其href属性以lacie结尾
soup.select('a[href$="lacie"]')
# 选择a标签,其href属性包含.com
soup.select('a[href*=".com"]')
# 从html中排除某标签,此时soup中不再有script标签
[s.extract() for s in soup('script')]
# 如果想排除多个呢
[s.extract() for s in soup(['script','fram']

  

1、通过标签选择

1
2
3
4
5
6
7
8
9
10
11
12
# 选择所有title标签
soup.select("title")
# 选择所有p标签中的第三个标签
soup.select("p:nth-of-type(3)") 相当于soup.select(p)[2]
# 选择body标签下的所有a标签
soup.select("body a")
# 选择body标签下的直接a子标签
soup.select("body > a")
# 选择id=link1后的所有兄弟节点标签
soup.select("#link1 ~ .mysis")
# 选择id=link1后的下一个兄弟节点标签
soup.select("#link1 + .mysis")

  2、通过类名查找

1
2
# 选择a标签,其类属性为mysis的标签
soup.select("a.mysis")

  3、通过id查找

1
2
# 选择a标签,其id属性为link1的标签
soup.select("a#link1")

  4、通过【属性】查找,当然也适用于class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 选择a标签,其属性中存在myname的所有标签
soup.select("a[myname]")
# 选择a标签,其属性href=http://example.com/lacie的所有标签
soup.select("a[href='http://example.com/lacie']")
# 选择a标签,其href属性以http开头
soup.select('a[href^="http"]')
# 选择a标签,其href属性以lacie结尾
soup.select('a[href$="lacie"]')
# 选择a标签,其href属性包含.com
soup.select('a[href*=".com"]')
# 从html中排除某标签,此时soup中不再有script标签
[s.extract() for s in soup('script')]
# 如果想排除多个呢
[s.extract() for s in soup(['script','fram']

soup.select的用法的更多相关文章

  1. linux c语言 select函数用法

    linux c语言 select函数用法 表头文件 #i nclude<sys/time.h> #i nclude<sys/types.h> #i nclude<unis ...

  2. Beautiful Soup库基础用法(爬虫)

    初识Beautiful Soup 官方文档:https://www.crummy.com/software/BeautifulSoup/bs4/doc/# 中文文档:https://www.crumm ...

  3. 数据库中增加操作insert into的用法和查询select的用法

    insert into的用法 1.一条insert into 可以插入多条记录 2.insert into 能判断主键是否冲突,和做出冲突处理 如果主键冲突的话会报错,还能写成如果冲突就更新的形式格式 ...

  4. select()函数用法二

    Select在Socket编程中还是比较重要的,可是对于初学Socket的人来说都不太爱用Select写程序,他们只是习惯写诸如 connect.accept.recv或recvfrom这样的阻塞程序 ...

  5. golang的select典型用法

    golang 的 select 的功能和 select, poll, epoll 相似, 就是监听 IO 操作,当 IO 操作发生时,触发相应的动作. 示例: ch1 := make (chan in ...

  6. mysql select简单用法

    1.select语句可以用回车分隔 $sql="select * from article where id=1" 和 $sql="select * from artic ...

  7. LINQ学习:Select的用法

    转载于:http://www.cnblogs.com/ForEvErNoME/archive/2012/07/25/2606659.html 说明:在查询表达式中,select 子句可以指定将在执行查 ...

  8. SQL语句中的select高级用法

    #转载请联系 为了更好的了解下面的知识点,我们先创建两张表并插入数据. # 学生表 +----+-----------+------+--------+--------+--------+------ ...

  9. SQL SERVER 2012 第三章 T-SQL 基本SELECT语句用法,Where子句详细用法

    select [all|distinct] [top (<expression>) [Percent] [with ties]] <column list> [from < ...

随机推荐

  1. flask实战-个人博客-数据库-生成虚拟数据 --

    3.生成虚拟数据 为了方便编写程序前台和后台功能,我们在创建数据库模型后就编写生成虚拟数据的函数. 1)管理员 用于生成虚拟管理员信息的fake_admin()函数如下所示: personalBlog ...

  2. zookeper分布式搭建

    zookeper的安装如下链接 https://www.cnblogs.com/wanerhu/p/11144815.html

  3. CentOS7 最小安装 vmware 创建虚拟机 nmcli ip systemctl

    镜像网站 一些开源软件的国内镜像源 站点版 (一).企业站 1.搜狐:http://mirrors.sohu.com/ 2.网易:http://mirrors.163.com/ 3.阿里云:http: ...

  4. 访问阿里云 vue项目的 127.0.0.1:+ip

    vue 127.0.0.1 将  localhost 改为 0.0.0.0 原理看下面链接 参考: https://www.cnblogs.com/sddai/p/9281189.html

  5. 仿照addCleanup 在unittest中清理addSetupclass资源

    addCleanup的用例这里不介绍了,可以看我的另一编文章: python unittest框架中addCleanup函数详解 但如果有下面这种场景,还是会遗留大批理资源 在setUpClass注入 ...

  6. HTML基础一-html、CSS

    一.HTML标签 前端语言 HTML-将页面展现出来    CSS-修饰前端标签 让HTML更好看 css 对html 进行修饰    JS-能够让页面动起来 HTML htyper text mar ...

  7. 提高 Visualforce 页面加载效率的小知识

    一般原则 在设计页面时,我们要将页面的功能降至最少,不要包含多余的功能和数据,以最大化提高运行效率 如果需要开发的功能可以通过 Salesforce 的标准功能实现,那么尽量使用标准功能,比如 工作流 ...

  8. Rpm Creating Subpackages

    转自:http://ftp.rpm.org/max-rpm/s1-rpm-subpack-spec-file-changes.html Spec File Changes For Subpackage ...

  9. day 14

    Sow an act, and you reap a habit. Sow a habit, and you reap a character. Sow a character, and you re ...

  10. 20165230田坤烨网络对抗免考报告_Windows系统提权

    目录 KERNEL EXPLOITATION 服务攻击: DLL劫持 攻击 不安全的服务权限 探测 unquoted path未被引号标记的路径 探测 攻击 服务注册表键 探测 攻击 Named Pi ...