문제

이것은 WordPress 게시물 세부 사항 페이지의 수프입니다.

content = soup.body.find('div', id=re.compile('post'))
title = content.h2.extract()
item['title'] = unicode(title.string)
item['content'] = u''.join(map(unicode, content.contents))

나는 동봉을 생략하고 싶습니다 div 할당 할 때 태그 item['content']. 유니 코드에서 태그의 모든 자식 태그를 렌더링하는 방법이 있습니까? 같은 것 :

item['content'] = content.contents.__unicode__()

그것은 나에게 목록 대신 단일 유니 코드 문자열을 줄 것이다.

도움이 되었습니까?

해결책

시도 했습니까?

unicode(content)

그것은 변환합니다 content단일 유니 코드 문자열에 대한 마크 업.

편집 : 둘러싸는 태그를 원하지 않으면 시도하십시오.

content.renderContents()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top