Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.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 用漂亮的汤拉屎-导航_Python_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 用漂亮的汤拉屎-导航

Python 用漂亮的汤拉屎-导航,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我正试图用漂亮的汤刮一个网站。我可以导航到类对象,但无法进入下一个级别以获取所需的文本 到目前为止我有 soup = BeautifulSoup(urllib2.urlopen('URL...').read()) comment = soup('div', {'class' : 'PanelDarkBackground'}) print comment 它只输出整个类(如下)。我只想提取代码的tr>td id=“event”部分中的0-0 有什么建议吗 [<div class="Pa

我正试图用漂亮的汤刮一个网站。我可以导航到类对象,但无法进入下一个级别以获取所需的文本

到目前为止我有

soup = BeautifulSoup(urllib2.urlopen('URL...').read())

comment = soup('div', {'class' : 'PanelDarkBackground'})
print comment 
它只输出整个类(如下)。我只想提取代码的tr>td id=“event”部分中的0-0

有什么建议吗

[<div class="PanelDarkBackground" id="Event-Basic-Info" style="margin-bottom: 10px">
<div style="height: 70px; width: 100%;">
<div style="height: 70px; width: 70px; float: left; background-color: white">
<img height="70" src="ss" width="70"/>
</div>
<div style="width: 450px; float: left; height: 70px; display: table">
<table border="0" cellpadding="0" cellspacing="0" style="font-family: tahoma; font-size:      18pt; font-weight: bold; color: white;" width="450px">

    <tr>
      <td align="center" height="70" style="font-family: tahoma; font-size: 18pt; font-weight:    bold; color: white;" valign="middle" width="197">seveal</td>
      <td align="center" id="event" style="font-family: tahoma; font-size: 18pt; font- weight: bold; color: white;" valign="middle">0-0</td>
      <td align="center" style="font-family: tahoma; font-size: 18pt; font-weight: bold; color: white;" valign="middle" width="197">seveal</td>
    </tr>
 </table>
</div>
<div style="height: 70px; width: 70px; float: right; background-color: white">
<img height="70" src="" width="70"/>
</div>
</div>
</div>]
[
塞维尔
0-0
塞维尔
]

直接转到
td

print soup('td',{'id':'event'})
对于
td
的内容,您可以执行以下操作:

print soup('td',{'id':'event'})[0].contents[0]

为什么不直接搜索给出的id呢?它在每一页中都应该是唯一的