Find next siblings until a certain one using beautifulsoup(使用 beautifulsoup 查找下一个兄弟姐妹,直到某个兄弟姐妹)
问题描述
网页是这样的:
我怎样才能找到其中包含文章的每个部分?即找到h2后,找到nextsiblings
直到下一个h2.
如果网页是这样的:(通常是这种情况)
我可以写如下代码:
但是如果我想获得相同的结果,我应该如何处理第一个网页呢?
我认为你可以这样做:
给定:
输出:
The webpage is something like this:
How can I find each section with articles within them? That is, after finding h2, find nextsiblings
until the next h2.
If the webpage were like: (which is normally the case)
I can write codes like:
But what should I do with the first webpage if I want to get the same result?
I think you can do something like this:
Given:
Output:
这篇关于使用 beautifulsoup 查找下一个兄弟姐妹,直到某个兄弟姐妹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!