Python 使用BeautifulSoup在ContentPane中查找没有标记的文本
我的问题与此类似:, 如何从ContentPane获取此文本:Python 使用BeautifulSoup在ContentPane中查找没有标记的文本,python,html,beautifulsoup,Python,Html,Beautifulsoup,我的问题与此类似:, 如何从ContentPane获取此文本:更新于2018年9月11日(57)个案例+(1)有海洛因贡献的交通量 HTML: <!--Container Content--> <div class="contentmain"> <div id="dnn_ctr3799_ContentPane" class="contentpane"> <!--Start_Module_3799--> Up
更新于2018年9月11日(57)个案例+(1)有海洛因贡献的交通量
HTML:
<!--Container Content-->
<div class="contentmain">
<div id="dnn_ctr3799_ContentPane" class="contentpane">
<!--Start_Module_3799-->
Updated September 11, 2018 (57) Cases + (1) traffic w/contributing heroin
texts = soup.find('div', id='dnn_ctr3799_ContentPane')
name = texts.find_next(string=True)
print od.nextSibling.string
尝试2nextSibling
:
我尝试了下一步升级,但没有结果
texts = soup.findAll("div", {"id":"dnn_ctr3799_ContentPane"})
for text in texts:
if text.string:
if "dnn_ctr3799_ContentPane" in text.string:
print text.nextSibling.string.strip()
链接到网页:原来它是我正在处理的一个容器。我想要的字符串是父
回答:
<!--Container Content-->
<div class="contentmain">
<div id="dnn_ctr3799_ContentPane" class="contentpane">
<!--Start_Module_3799-->
Updated September 11, 2018 (57) Cases + (1) traffic w/contributing heroin
texts = soup.find('div', id='dnn_ctr3799_ContentPane')
name = texts.find_next(string=True)
print od.nextSibling.string