BS4 select_one vs查找 [英] Bs4 select_one vs find

查看:146
本文介绍了BS4 select_one vs查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道执行bs.find('div')bs.select_one('div')有什么区别. find_allselect也是如此.

I was wondering what is the difference between performing bs.find('div') and bs.select_one('div'). Same goes for find_all and select.

在性能上是否存在差异,或者在特定情况下是否比其他方法更好?

Is there any difference performance wise, or if any is better to use over the other in specific cases.

推荐答案

select()select_one()提供了使用

select() and select_one() give you a different way navigating through an HTML tree using the CSS selectors which has rich and convenient syntax. Though, the CSS selector syntax support in BeautifulSoup is limited but covers most common cases.

就性能而言,它实际上取决于要解析的HTML树以及哪个元素,元素的深度以及用于定位它的选择器.另外,用于比较select()find() + find_all()替代方案也很重要.在bs.find('div')bs.select_one('div')之类的简单情况下,我想通常说find()应该执行得更快,因为

Performance-wise, it really depends on an HTML tree to parse and on which element, how deep is it and what selector is used to locate it. Plus, what find() + find_all() alternative there is to compare the select() with, is also important. In a simple case like bs.find('div') vs bs.select_one('div'), I'd say that, generally, find() should perform faster simply because there is a lot going on to support CSS selector syntax under-the-hood.

这篇关于BS4 select_one vs查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆