我正在使用BeautifulSoup在特定页面上查找用户输入的字符串.例如,我想看看字符串'Python'是否位于页面上:http://python.org
当我使用:
find_string = soup.body.findAll(text='Python')
find_string返回[]
但是当我使用:
find_string = soup.body.findAll(text=re.compile('Python'), limit=1)
find_string [u'Python Jobs']按预期返回
这两个语句之间的区别是,当要搜索的单词有多个实例时,第二个语句会起作用
commentary = soup.find('div', {'id' : 'live-text-commentary-wrapper'})
findtoure = commentary.findAll(text = 'Gnegneri Toure Yaya')
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这不起作用。
评论的输出是:
<div id="live-text-commentary-wrapper">
<h2 id="live-text-introduction">Live Text Commentary</h2>
<div class="live-text blq-clearfix" id="live-text">
<span>90:00
<span class="extra-info">+3:04
<span class="icon-live-text-full-time">Full time</span></span></span>
<p class="event">
<span class="event-title">
<strong>Full Time</strong>
</span> The referee ends the match.</p>
<span>90:00
<span class="extra-info">+2:52</span></span>
<p>Gael Clichy produces a cross, clearance made by Mike Williamson.</p>
<span>90:00
<span class="extra-info">+0:41</span></span>
<p>Shot by Shola Ameobi from 20 yards. Save made by Joe Hart.</p>
<span>90:00
<span class="extra-info">+0:07</span></span>
<p>The ball is crossed by Davide …Run Code Online (Sandbox Code Playgroud)