为什么打印的不是Hello, 而是None
来源:4-7 BeautifulSoup4之获取父节点、祖先节点、兄弟节点
大可计划
2021-09-01 10:48:13
import requests
from bs4 import BeautifulSoup
html = """
<html>
<body>
<p class="story">
Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">
<span>Elsie</span>
</a>
Hello
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a>
and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
and they lived at the bottom of a well.
</p>
"""
soup = BeautifulSoup(html, 'lxml')
print(soup.a.next_subling)
1回答
同学,你好!获取下一个兄弟节点是next_sibling,同学写错了
祝学习愉快!
相似问题