제거 :파이썬 : HTML 코드를 구문 분석하는 동안 줄을 건너 뛰고 나는 <code>html</code> 다음 코드 한 공백
html_doc = """
<h2> API guidance for developers</h2>
<h2>Images</h2>
<h2>Score descriptors</h2>
<h2>Downloadable XML data files (updated daily)</h2>
<h2>
East Counties</h2>
<h2>
East Midlands</h2>
<h2>
London</h2>
<h2>
North East</h2>
<h2>
North West</h2>
<h2>
South East</h2>
<h2>
South West</h2>
<h2>
West Midlands</h2>
<h2>
Yorkshire and Humberside</h2>
<h2>
Northern Ireland</h2>
<h2>
Scotland</h2>
<h2>
Wales</h2>
"""
내가 처음 네 줄을 건너 뛰고 등과 East Counties
등의 텍스트 문자열에 액세스 할 수있는 방법 ?
처음 네 줄을 건너 뛰고 (내가 제거 할) 코드에 포함 많은 공백을 포함한 문자열 반환하지 않습니다 내 시도 :
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc, 'html.parser')
for h2 in soup.find_all('h2'):
next
next
next
next
print (str(h2.children.next()))
원하는 결과 :
를East Counties
East Midlands
London
North East
...
내가 뭘 잘못하고 있니?
왜 당신은 그냥 사용할 수없는 사용 무시 'soup.find_all ('h2') [4 :]'? – Sraw