2017-02-15 2 views
0

내가 연구 목적이 url를 크롤링하기 위해 노력하고있어 BeautifulSoup로 함수 발견()를 호출,하지만 난 불완전한 결과를 얻을 때 :불완전한 결과

<div class="entry"> 
<header><strong>Racial Forensics in an Age of Race Denial</strong></header></div> 
:

opener = urllib.request.build_opener() 
opener.addheaders = [('User-Agent', 'Mozilla/5.0')] 
response = opener.open(url) 
soup = BeautifulSoup(response, 'html.parser') 
article = soup.find("div", { "class" : "entry" }) 
print(article) 

그것은 나에게이 결과를 제공을

하지만 페이지의 코드 소스보고있을 때 나는 더 많이 볼 수 있습니다

<div class="entry"> 
<header><strong>Racial Forensics in an Age of Race Denial</strong></p> 
</header> 
<p>Austen Layard<br/> 
<a href="http://www.theoccidentalobserver.net/2014/01/racial-forensics-in-an-age-of-race-denial/"><strong>Occidental Observer</strong></a><br/> 
February 3, 2014</p> 
.... 
</div> 

T 이 URL과 제가 처리 한 많은 다른 점 사이의 차이는 태그 header의 존재입니다.

태그가 내 문제의 근원입니까? div 태그의 전체 내용을 검색하려면 어떻게해야합니까?

+0

@MYGz는 작동하지 않습니다. – mel

답변

1
soup = BeautifulSoup(response, 'lxml') 

html.parser는 기본적으로 불안정하고 매우 권장되지이다, BS4는 lxml를 사용의 기본와 함께 머물 수 있습니다.