Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python Beautifulsoup获取特定的NHL分数_Python_Html_Web Scraping_Beautifulsoup_Html Parsing - Fatal编程技术网

使用Python Beautifulsoup获取特定的NHL分数

使用Python Beautifulsoup获取特定的NHL分数,python,html,web-scraping,beautifulsoup,html-parsing,Python,Html,Web Scraping,Beautifulsoup,Html Parsing,我试图只为一个特定的团队取得总分。我写了以下内容: import urllib.request import re from bs4 import BeautifulSoup #url1 = "http://scores.nbcsports.com/nhl/scoreboard.asp" ## This works, however is using a set day for testing, will need url changed to url1 for current day sc

我试图只为一个特定的团队取得总分。我写了以下内容:

import urllib.request
import re
from bs4 import BeautifulSoup

#url1 = "http://scores.nbcsports.com/nhl/scoreboard.asp"

## This works, however is using a set day for testing, will need url changed to url1 for current day scoreboard
url = "http://scores.nbcsports.com/nhl/scoreboard.asp?day=20141202"
page = urllib.request.urlopen(url)
soup = BeautifulSoup(page)

allrows = soup.findAll('td')
userows = [t for t in allrows if t.findAll(text=re.compile('Vancouver'))]

print(userows)
这将返回:

[<td><table cellspacing="0"><tr class="shsTableTtlRow"><td class="shsNamD" colspan="1">Final</td>
<td class="shsTotD">1</td>
<td class="shsTotD">2</td>
<td class="shsTotD">3</td>
<td class="shsTotD">Tot</td>
</tr>
<tr>
<td class="shsNamD" nowrap=""><span class="shsLogo"><span class="shsNHLteam22sm_trans"></span></span><a href="/nhl/teamstats.asp?teamno=22&amp;type=stats">Vancouver</a></td>
<td class="shsTotD">1</td>
<td class="shsTotD">2</td>
<td class="shsTotD">1</td>
<td class="shsTotD">4</td>
</tr>
<tr>
<td class="shsNamD" nowrap=""><span class="shsLogo"><span class="shsNHLteam23sm_trans"></span></span><a href="/nhl/teamstats.asp?teamno=23&amp;type=stats">Washington</a></td>
<td class="shsTotD">0</td>
<td class="shsTotD">2</td>
<td class="shsTotD">1</td>
<td class="shsTotD">3</td>
</tr>
</table>
</td>, <td class="shsNamD" nowrap=""><span class="shsLogo"><span class="shsNHLteam22sm_trans"></span></span><a href="/nhl/teamstats.asp?teamno=22&amp;type=stats">Vancouver</a></td>]
[最终版本]
1.
2.
3.
托特
1.
2.
1.
4.
0
2.
1.
3.
, ]

我似乎找不到中间块的
4
中的4。如果只可能得到1 2 1 4值,我可以比较这些值并总是选择最大的,但我似乎都走不了那么远。提前感谢。

找到包含
温哥华
的标签,然后使用以下方法获取下一个
td
标签:

印刷品:

1
2
1
4

谢谢,正是我需要的。
1
2
1
4