2012-05-09 5 views
1
import urllib2 
from BeautifulSoup import BeautifulSoup 

result = urllib2.urlopen("http://www.bbc.co.uk/news/uk-scotland-south-scotland-12380537") 
html=result.read() 
soup= BeautifulSoup(html) 
print soup.html.head.title 

print soup.findAll('div', attrs={ "class" : "story-body"}) 

내가 원하는 정보는 스토리 본문에있는 것 같지만 맨 아래에 있습니다. 그래서 나는 거기에 도착할 때까지 많은 정보를 얻는다.beautifulsoup에서 findAll을 (를) 사용하여 필터링 한 결과

print soup.findAll('p', attrs={ 'class' : "introduction"}) 

만 나에게 얻는 첫번째

그래서 ... 이야기 - 몸의 끝에 도입의 시작에서 수집하는 모든 아이디어를 찾고이 예에서는 수집이 더가? CSS 선택기의 측면에서

답변