相关疑难解决方法(0)

使用BeautifulSoup在html中搜索字符串

我正在使用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']按预期返回

这两个语句之间的区别是,当要搜索的单词有多个实例时,第二个语句会起作用

python beautifulsoup

43
推荐指数
3
解决办法
8万
查看次数

Python - Beautiful Soup 查找文本不起作用

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)

python beautifulsoup

2
推荐指数
1
解决办法
5347
查看次数

标签 统计

beautifulsoup ×2

python ×2