美文网首页
BeautifulSoup之select_one(),selec

BeautifulSoup之select_one(),selec

作者: 二十二_0cbe | 来源:发表于2019-05-27 15:12 被阅读0次

在爬去网页的时候,会用到这几个函数,很好奇他们几个有什么区别,于是测试了一下。
测试网址:https://dict.eudic.net/webting/play?id=e27a4e2d-f7dc-442a-937e-6b10691275e5&order=0
具体执行:

    response = requests.get(url)
    soup = BeautifulSoup(response.content, "html.parser")
    test1 = soup.select_one('span.sentence')
    test2 = soup.select('span.sentence')
    test4 = soup.find(name='span', class_='sentence')
    test5 = soup.find_all(name='span', class_='sentence')

得到:


运行截图

只根据上面的结果来看,select_one()与find()是完全相同的,select()与find_all()得到的结果相同,只有结果类型不同,select()得到的结果是‘list’类型,find_all()得到的结果是'bs4.element.ResultSet'类型。
然后很好奇吼,select()子元素类型嘞?'bs4.element.ResultSet'类型有什么特殊的吗?
Then-->
看了一下test2第一个元素的类型和test5的属性:


type(test2[0])和test5.source
以及type(test5.source):
source的类型

好奇心探索完毕!继续回去码代···

相关文章

  • BeautifulSoup之select_one(),selec

    在爬去网页的时候,会用到这几个函数,很好奇他们几个有什么区别,于是测试了一下。测试网址:https://dict....

  • 1.2解析网页

    使用BeautifulSoup解析网页 描述要爬取的东西在哪 从标签中获取信息,并装在数据容器中CSS Selec...

  • 爬虫2

    爬虫之 beautifulsoup BeautifulSoup3目前已经停止开发,推荐现在的项目使用Beautif...

  • 爬虫

    爬虫之 beautifulsoup BeautifulSoup3目前已经停止开发,推荐现在的项目使用Beautif...

  • Selector & SEL

    Objective-C中的Runtime 消息处理之performSelector IOS SEL (@selec...

  • 爬虫任务二

    2.1 学习beautifulsoup 学习beautifulsoup,并使用beautifulsoup提取内容。...

  • Python之BeautifulSoup

    BeautifulSoup是什么 一个灵活方便的网页解析库,处理高效,支持多种解析器 利用他不用编写正则表达式即可...

  • BeautifulSoup(BS4)的基本使用

    一、BeautifulSoup简介 二、BeautifulSoup安装 三、BeautifulSoup基本使用 导...

  • BeautifulSoup基础使用

    1. 安装BeautifulSoup BeautifulSoup官方文档 BeautifulSoup安装命令:co...

  • beautifulsoup教程

    beautifulsoup教程 BeautifulSoup4是爬虫必学的技能。BeautifulSoup最主要的功...

网友评论

      本文标题:BeautifulSoup之select_one(),selec

      本文链接:https://www.haomeiwen.com/subject/ahdhtctx.html