Beautiful Soup 简明教程
Beautiful Soup - find_next_sibling() Method
Method Description
Beautiful Soup 中的 find_next_sibling() 方法查找与给定条件匹配的,且在文档中之后出现的,在这个 PageElement 中的同级中最接近的同级。此方法类似于 next_sibling 属性。
The find_next_sibling() method in Beautiful Soup Find the closest sibling at the same level to this PageElement that matches the given criteria and appears later in the document. This method is similar to next_sibling property.
Parameters
-
name − A filter on tag name.
-
attrs − A dictionary of filters on attribute values.
-
string − The string to search for (rather than tag).
-
kwargs − A dictionary of filters on attribute values.
Return Type
find_next_sibling() 方法返回 Tag 对象或 NavigableString 对象。
The find_next_sibling() method returns Tag object or a NavigableString object.
Example 1
from bs4 import BeautifulSoup
soup = BeautifulSoup("<p><b>Hello</b><i>Python</i></p>", 'html.parser')
tag1 = soup.find('b')
print ("next:",tag1.find_next_sibling())