- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
commentary = soup.find('div', {'id' : 'live-text-commentary-wrapper'})
findtoure = commentary.findAll(text = 'Gnegneri Toure Yaya')
我不明白为什么这不起作用。
评论的输出是:
<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 Santon, Demba Ba has an effort at goal. Joe Hart makes a save.</p>
<span>88:26</span>
<p>Assist by Gael Clichy.</p>
<span>88:26
<span class="extra-info">
<span class="icon-live-text-goal">Goal scored</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Goal</strong> - Gnegneri Toure Yaya -
<strong>Newcastle 0 - 2 Man City</strong></span> Gnegneri Toure Yaya grabs a goal from close in high into the middle of the
goal. Newcastle 0-2 Man City.</p>
<span>88:00</span>
<p>Inswinging corner taken by Yohan Cabaye from the left by-line played to the near post, Vincent Kompany manages to make a
clearance.</p>
<span>87:45</span>
<p>Shola Ameobi has a drilled shot. Micah Richards gets a block in.</p>
<span>87:13</span>
<p>The ball is swung over by Sergio Aguero, clearance made by Shola Ameobi.</p>
<span>85:05
<span class="extra-info">
<span class="icon-live-text-substitution">Substitution</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Substitution</strong>
</span> (Man City) makes a substitution, with Micah Richards coming on for David Silva.</p>
<span>84:24</span>
<p>Shola Ameobi gives away a free kick for an unfair challenge on Joleon Lescott. Joe Hart restarts play with the free
kick.</p>
<span>83:43</span>
<p>Inswinging corner taken left-footed by David Silva from the right by-line to the near post, Shot from close range by
Edin Dzeko clears the bar.</p>
<span>83:17</span>
<p>Sergio Aguero takes a shot. Save by Tim Krul.</p>
<span>81:44
<span class="extra-info">
<span class="icon-live-text-substitution">Substitution</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Substitution</strong>
</span> Cheick Tiote goes off and Ryan Taylor comes on.</p>
<span>80:42</span>
<p>Cheick Tiote gives away a free kick for an unfair challenge on Pablo Zabaleta. The ball is sent over by David Silva,
Close range header by Gnegneri Toure Yaya goes wide of the left-hand upright.</p>
<span>79:46</span>
<p>Joe Hart takes the direct free kick.</p>
<span>79:46
<span class="extra-info">
<span class="icon-live-text-booking">Booking</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Booking</strong>
</span> Shane Ferguson receives a yellow card for unsporting behaviour.</p>
<span>79:38</span>
<p>Shane Ferguson gives away a free kick for an unfair challenge on David Silva.</p>
<span>78:58</span>
<p>Free kick crossed by Yohan Cabaye, clearance by Gareth Barry.</p>
<span>78:58
<span class="extra-info">
<span class="icon-live-text-booking">Booking</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Booking</strong>
</span> Pablo Zabaleta goes into the book for unsporting behaviour.</p>
</div>
<div class="live-text blq-clearfix" id="more-live-text">
<span>78:50</span>
<p>Free kick awarded for an unfair challenge on Shane Ferguson by Pablo Zabaleta.</p>
<span>77:41</span>
<p>The ball is crossed by Cheick Tiote, Edin Dzeko manages to make a clearance.</p>
<span>74:24</span>
<p>Shot by Sergio Aguero from deep inside the penalty area misses to the right of the target.</p>
<span>76:38</span>
<p>Corner taken by Yohan Cabaye from the left by-line to the near post, clearance made by Gareth Barry.</p>
<span>76:19</span>
<p>The ball is swung over by Yohan Cabaye, save by Joe Hart.</p>
<span>75:48</span>
<p>Centre by Pablo Zabaleta.</p>
<span>74:26</span>
<p>Shola Ameobi crosses the ball, Headed effort from inside the area by Papiss Cisse misses to the right of the goal.</p>
<span>74:24</span>
<p>Sergio Aguero produces a right-footed shot from deep inside the penalty area which goes wide of the right-hand post.</p>
<span>73:52
<span class="extra-info">
<span class="icon-live-text-substitution">Substitution</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Substitution</strong>
</span> Shola Ameobi joins the action as a substitute, replacing Hatem Ben Arfa.</p>
<span>73:32
<span class="extra-info">
<span class="icon-live-text-substitution">Substitution</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Substitution</strong>
</span> Shane Ferguson replaces James Perch.</p>
<span>73:17</span>
<p>Edin Dzeko has an effort at goal from deep inside the area missing to the left of the goal.</p>
<span>72:36</span>
<p>Gareth Barry fouled by Papiss Cisse, the ref awards a free kick. Direct free kick taken by Nigel De Jong.</p>
<span>69:42</span>
<p>Sergio Aguero provided the assist for the goal.</p>
<span>69:42
<span class="extra-info">
<span class="icon-live-text-goal">Goal scored</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Goal</strong> - Gnegneri Toure Yaya -
<strong>Newcastle 0 - 1 Man City</strong></span> Goal scored by Gnegneri Toure Yaya from just outside the penalty box to
the bottom right corner of the goal. Newcastle 0-1 Man City.</p>
<span>69:02
<span class="extra-info">
<span class="icon-live-text-substitution">Substitution</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Substitution</strong>
</span> Edin Dzeko joins the action as a substitute, replacing Carlos Tevez.</p>
<span>66:49</span>
<p>Demba Ba sends in a cross, Joleon Lescott manages to make a clearance.</p>
<span>66:28</span>
<p>Shot by Demba Ba from 18 yards. Clearance by Gareth Barry.</p>
<span>65:23</span>
<p>Centre by David Silva, Joleon Lescott challenges Tim Krul unfairly and gives away a free kick. Direct free kick taken by
Tim Krul.</p>
<span>65:01</span>
<p>Inswinging corner taken left-footed by David Silva played to the near post, Papiss Cisse makes a clearance.</p>
<span>64:54</span>
<p>The ball is swung over by Carlos Tevez, clearance by Fabricio Coloccini.</p>
<span>64:01</span>
<p>Effort on goal by Hatem Ben Arfa from inside the penalty box misses to the right of the target.</p>
<span>60:56
<span class="extra-info">
<span class="icon-live-text-substitution">Substitution</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Substitution</strong>
</span> Nigel De Jong replaces Samir Nasri.</p>
<span>58:44</span>
<p>David Silva has an effort at goal. Blocked by Mike Williamson.</p>
<span>57:51</span>
<p>The ball is crossed by James Perch, clearance by Joleon Lescott.</p>
<span>57:05</span>
<p>Foul by Jonas Gutierrez on Sergio Aguero, free kick awarded. Free kick taken by Gareth Barry.</p>
<span>56:55</span>
<p>Cheick Tiote crosses the ball, Samir Nasri makes a clearance.</p>
<span>56:20</span>
<p>Free kick awarded for an unfair challenge on Davide Santon by Gnegneri Toure Yaya. Free kick taken by Yohan Cabaye.</p>
<span>54:36</span>
<p>Shot from 20 yards from Carlos Tevez. Save made by Tim Krul.</p>
<span>53:17</span>
<p>Carlos Tevez produces a right-footed shot from the edge of the box and misses to the right of the target.</p>
<span>53:01</span>
<p>Centre by David Silva, Jonas Gutierrez makes a clearance.</p>
<span>52:44</span>
<p>Short corner taken by Samir Nasri.</p>
<span>52:33</span>
<p>Gael Clichy sends in a cross, blocked by James Perch.</p>
<span>50:17</span>
<p>Free kick awarded for an unfair challenge on Carlos Tevez by James Perch. Gnegneri Toure Yaya has an effort direct from
the free kick.</p>
<span>49:41</span>
<p>Jonas Gutierrez sends in a cross, Pablo Zabaleta gets a block in.</p>
<span>48:02</span>
<p>Foul by Jonas Gutierrez on Pablo Zabaleta, free kick awarded. Joe Hart restarts play with the free kick.</p>
<span>47:10</span>
<p>The ball is swung over by Papiss Cisse, clearance made by Joleon Lescott.</p>
<span>45:01</span>
<p>The match restarts for the second half.</p>
<span>45:00
<span class="extra-info">+1:09
<span class="icon-live-text-half-time">Half time</span></span></span>
<p class="event">
<span class="event-title">
<strong>Half Time</strong>
</span> The half-time whistle blows.</p>
<span>45:00
<span class="extra-info">+0:07</span></span>
<p>The referee blows for offside against Gareth Barry. Tim Krul takes the free kick.</p>
<span>43:30</span>
<p>Demba Ba gives away a free kick for an unfair challenge on Vincent Kompany. Free kick taken by Joe Hart.</p>
<span>41:43</span>
<p>Handball by Samir Nasri. Free kick taken by Tim Krul.</p>
<span>41:32</span>
<p>The ball is swung over by Sergio Aguero.</p>
<span>40:35</span>
<p>Gareth Barry has an effort at goal from 12 yards. Fabricio Coloccini gets a block in. Shot from 12 yards by Gareth
Barry. Clearance made by Davide Santon.</p>
<span>39:22</span>
<p>A cross is delivered by Hatem Ben Arfa, Demba Ba produces a header from inside the area that goes over the bar.</p>
<span>37:52</span>
<p>Yohan Cabaye takes the free kick.</p>
<span>37:52
<span class="extra-info">
<span class="icon-live-text-booking">Booking</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Booking</strong>
</span> Gnegneri Toure Yaya goes into the referee's book for unsporting behaviour.</p>
<span>37:44</span>
<p>Free kick awarded for an unfair challenge on Davide Santon by Gnegneri Toure Yaya.</p>
<span>36:55</span>
<p>The ball is swung over by Pablo Zabaleta.</p>
<span>35:57</span>
<p>Gnegneri Toure Yaya takes the free kick.</p>
<span>35:57
<span class="extra-info">
<span class="icon-live-text-booking">Booking</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Booking</strong>
</span> The referee books James Perch for unsporting behaviour.</p>
<span>35:38</span>
<p>James Perch concedes a free kick for a foul on Carlos Tevez.</p>
<span>34:26</span>
<p>Yohan Cabaye produces a right-footed shot from just outside the box that goes wide left of the goal.</p>
<span>33:42</span>
<p>Shot from 12 yards from Demba Ba. Blocked by Gael Clichy. Shot by Hatem Ben Arfa from 12 yards. Save by Joe Hart.</p>
<span>31:37</span>
<p>David Silva crosses the ball in from the free kick.</p>
<span>31:37
<span class="extra-info">
<span class="icon-live-text-booking">Booking</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Booking</strong>
</span> Cheick Tiote receives a caution for unsporting behaviour.</p>
<span>31:25</span>
<p>Free kick awarded for a foul by Cheick Tiote on David Silva.</p>
<span>31:09</span>
<p>Drilled right-footed shot by Demba Ba. Blocked by Joleon Lescott.</p>
<span>30:40</span>
<p>Samir Nasri has a drilled shot. Yohan Cabaye gets a block in.</p>
<span>30:14</span>
<p>Shot by Cheick Tiote. Vincent Kompany gets a block in.</p>
<span>28:58</span>
<p>Yohan Cabaye fires a strike on goal direct from the free kick, Carlos Tevez gets a block in.</p>
<span>28:58
<span class="extra-info">
<span class="icon-live-text-booking">Booking</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Booking</strong>
</span> Gareth Barry goes into the referee's book.</p>
<span>28:51</span>
<p>Free kick awarded for a foul by Gareth Barry on Yohan Cabaye.</p>
<span>28:15</span>
<p>Demba Ba takes a shot from a long way out clearing the bar.</p>
<span>25:39</span>
<p>Shot comes in from Carlos Tevez from the free kick, Tim Krul makes a save.</p>
<span>25:39
<span class="extra-info">
<span class="icon-live-text-booking">Booking</span>
</span></span>
<p class="event">
<span class="event-title">
<strong>Booking</strong>
</span> Hatem Ben Arfa is cautioned.</p>
<span>25:29</span>
<p>Hatem Ben Arfa gives away a free kick for an unfair challenge on Gael Clichy.</p>
<span>22:48</span>
<p>The offside flag is raised against Sergio Aguero. Yohan Cabaye restarts play with the free kick.</p>
<span>22:05</span>
<p>The ball is crossed by Gael Clichy.</p>
<span>20:17</span>
<p>Long distance shot from Gael Clichy misses to the left of the goal.</p>
<span>19:44</span>
<p>Corner taken left-footed by David Silva from the right by-line, James Perch manages to make a clearance.</p>
<span>18:35</span>
<p>The ball is sent over by Pablo Zabaleta, clearance by Mike Williamson.</p>
<span>16:43</span>
<p>Sergio Aguero takes a shot. Tim Krul makes a save.</p>
<span>15:24</span>
<p>Papiss Cisse is flagged offside by the assistant referee. Free kick taken by Vincent Kompany.</p>
<span>10:15</span>
<p>Shot by David Silva. Save made by Tim Krul.</p>
<span>9:45</span>
<p>Corner taken by Samir Nasri from the left by-line to the near post, clearance made by Cheick Tiote.</p>
<span>9:18</span>
<p>Samir Nasri takes a short corner, David Silva sends in a cross, blocked by Hatem Ben Arfa.</p>
<span>8:54</span>
<p>Samir Nasri produces a curled right-footed shot from 18 yards. Blocked by James Perch.</p>
<span>6:31</span>
<p>Unfair challenge on Gareth Barry by Yohan Cabaye results in a free kick. Gnegneri Toure Yaya takes the direct free
kick.</p>
<span>4:33</span>
<p>Carlos Tevez is flagged offside by the assistant referee. Free kick taken by Tim Krul.</p>
<span>1:15</span>
<p>Free kick awarded for an unfair challenge on Hatem Ben Arfa by David Silva. Direct free kick taken by Yohan Cabaye.</p>
<span>0:06</span>
<p>Carlos Tevez concedes a free kick for a foul on Cheick Tiote. Yohan Cabaye takes the free kick.</p>
<span>0:00</span>
<p>The game kicks-off.</p>
</div>
<button class="hide blq-clearfix" id="show-more-live-text" style="display: none;" type="button">
<span class="text-indicator">More Live Text</span>
</button>
<p class="disclaimer">Live text and data provided by The Press Association</p>
</div>
我最终想用 'Yaya Toure'
替换 'Gnegneri Toure Yaya'
。
编辑 - 我想用 'Yaya Toure'
替换这些实例。但是我随后希望能够像以前一样使用整个评论正文,但进行了更改(如果我使用 find
然后 .replace
它用 'Gnegneri Toure Yaya'
但不更改原始注释变量。
最佳答案
像这样搜索 text
必须匹配标签中的整个文本,在您的例子中就是 - Gnegneri Toure Yaya -
。
改成正则表达式:
import re
findtoure = commentary.findAll(text = re.compile('Gnegneri Toure Yaya'))
这将匹配所有包含该名称的 NavigableString
元素。
关于Python - Beautiful Soup 查找文本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15054574/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!