我正在嘗試使用該findChildren()功能。我基本上想要所有<p>在特定<h3>標簽下。我正在嘗試一些簡單的代碼,但集合children。我要回來的是空的。h3返回正確的行(請參見print(h3)注釋)和print(type(children))打印類型:<class 'bs4.element.ResultSet'>。請告訴我我在做什么錯。soup = BeautifulSoup(contents, 'html.parser')h3 = soup.find('h3', text=re.compile('chapter', re.IGNORECASE))print(h3) #result prints <h3 style="text-align: center;">CHAPTER ONE - STEPHANUS GRAYLAND</h3> children = h3.findChildren('p')print(type(children)) #returns type: <class 'bs4.element.ResultSet'>我也試過h3.findChildren('p', Recursive=True)和children = h3.findChildren(Recursive=True)。里面也回來空了。這是我要抓取的HTML部分:<h3 style="text-align: center;">CHAPTER ONE - STEPHANUS GRAYLAND</h3><p dir="ltr" style="line-height: 1.15; margin-top: 0pt; margin-bottom: 0pt;"> <span style="font-size: 16px; font-family: 'Times New Roman'; background-color: transparent; vertical-align: baseline; white-space: pre-wrap;">Stephanus Grayland did not try to hide his smile of satisfaction . He had “eaten” lunch, but now, he sensed, he would truly </span> <span style="font-size: 16px; font-family: 'Times New Roman'; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">feast</span> <span style="font-size: 16px; font-family: 'Times New Roman'; background-color: transparent; vertical-align: baseline; white-space: pre-wrap;">.</span></p><p></p>
添加回答
舉報
0/150
提交
取消
