오늘 아침에 몇 시간을 들여서 긁힌 웹 페이지에서 문자열을 처리하려고 노력했다. 키워드를 확인할 수 있도록 추출 된 문자열을 일관되게 낮추는 방법을 사용할 수없는 것 같습니다. 여기 BeautifulSupTag, strings 및 UnicodeEncodeError가 너무 아름답 지 않다.
는 DOM 요소에서 텍스트를 검색하는 코드 조각입니다 :temp = i.find('div', 'foobar').find('div')
if temp is not None and temp.contents is not None:
temp2 = whitespace.sub(' ', temp.contents[0])
content = str(temp2)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 150: ordinal not in range(128)
나는 또한 다음과 같은 문장 시도 - 일 어느 것도을; 즉, 그들은 같은 오류가 발생했습니다가 발생되고 :
content = (str(temp2)).decode('utf-8').lower()
content = str(temp2.decode('utf-8')).lower()
사람이 소문자 ASCII로 BeautifulSoupTag에 포함 TEH 텍스트를 변환하는 방법을 알고 있나요, 그래서 키워드 (들)에 대한 대소 문자를 구분 검색을 수행 할 수 있습니다?
시도를하려고 : [문서] (http://www.crummy.com/software/BeautifulSoup/documentation.html#Beautiful 수프가 당신에게 유니 코드, 젠장 부여) – methyl
을 할 수 있습니다 그냥'unicode (temp2)'를 사용하면됩니까? –
[내 질문과 거의 같은 질문에 동의했습니다.] (http://stackoverflow.com/q/9012607/4279) – jfs