美丽的小组 - 在课堂上刮擦一个条件
例如,我有这个html,
<div class="item-1">a</div>
<div class="item-3">b</div>
<div class="item-6">c</div>
<div class="item-8">aaaaaa</div>
...... item-x keep increasing randomly on it class
<div class="item-100">aaaaaa</div>
我想删除所有类item-x,其中x的值在5到10之间,
我知道如何使用部分类名称搜索
text = soup.select('div[class*="item-"]')
,但是我不知道如何为其添加条件
for example I have this html
<div class="item-1">a</div>
<div class="item-3">b</div>
<div class="item-6">c</div>
<div class="item-8">aaaaaa</div>
...... item-x keep increasing randomly on it class
<div class="item-100">aaaaaa</div>
I want to scrap all of the class item-X where the value of X is between 5 to 10
I know how to search with a partial class name
text = soup.select('div[class*="item-"]')
but I don't know how to add conditions for it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以简单地用于循环。
You can simply use for loop.
您可以使用由
,
加入的多个CSS选择器:打印:
You can use multiple CSS selectors joined by
,
:Prints: