小编use*_*606的帖子

Python - 使用beautifulSoup查找文本,然后替换原始汤变量

commentary = soup.find('div', {'id' : 'live-text-commentary-wrapper'})
findtoure = commentary.find(text = re.compile('Gnegneri Toure Yaya')).replace('Gnegneri      Toure Yaya', 'Yaya Toure')
Run Code Online (Sandbox Code Playgroud)

评论包含需要改为Yaya Toure的Gnegneri Toure Yaya的各种情况.

findAll() 不起作用,因为findtoure是一个列表.

另一个问题我是这样的代码只是发现他们并且替换它们进入一个新的变量,名为findtoure,我需要更换他们原有的汤.

我想我只是从错误的角度看待这个问题.

python beautifulsoup

13
推荐指数
1
解决办法
1万
查看次数

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