이 코드를 실행 한 후
section = soup.find_all('section', class_='b-branches')
나는 얻다
<div class="b-branches__item"><i class="icon fa"><b>Firm</b> </i>RJT Roadlines</div>
이제는 RJIT Roadlines 만 추출하고 싶습니다.
그래서 나는 시도했다
for i in section: firm = i.find('div', class_='b-branches__item') print(firm)
회사 및 RJIT로드 라인을 모두 반환합니다.
그래서, div 태그의 텍스트 만 추출하는 방법 ??
tag.contents[1]
예상 출력을 얻는 데 사용할 수 있습니다 .
예:
from bs4 import BeautifulSoup
html = """
<div class="b-branches__item"><i class="icon fa"><b>Firm</b> </i>RJT Roadlines</div>
"""
soup=BeautifulSoup(html,'html.parser')
tag = soup.find('div', class_='b-branches__item')
print(tag.contents[1])
산출:
RJT Roadlines
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다