2013-02-06 3 views
2

나는 아름다운 수프를 사용하여 웹 사이트를 긁어 내려고합니다. 클래스 객체를 탐색 할 수는 있지만 원하는 수준의 텍스트를 얻을 수는 없습니다.아름다운 수프 네비게이션으로 웹 스크랩

지금까지 I는 전체 클래스 (아래)를 출력

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

comment = soup('div', {'class' : 'PanelDarkBackground'}) 
print comment 

있다. 0-0을 추출하고 싶습니다. 코드의 tr> td id = "event"섹션에 있습니다.

제안 사항 ...?

[<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

왜 그냥 포기 ID를 검색하지? 모든 페이지에서 고유해야합니다. – Vor

답변

2

바로 가기 td으로 이동하십시오. 당신이 할 수있는 td의 내용 만 들어

print soup('td',{'id':'event'}) 

:

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

감사합니다 !!! 그게 효과가 있지만, 전체 라인을 얻었는데, 나는 단지 0-0을 원했다 ...? – DavidJB

관련 문제