0
URL 페이지의 모든 주석을 긁어서 텍스트를 txt 파일 (1 개의 주석 = 1 개의 txt)에 저장합니다. 코멘트의 텍스트에 이모티가있을 때 문제가 있습니다. 사실, 프로그램이 멈추고 "UnicodeEncodeError : 'charmap'코덱이 문자를 인코딩 할 수 없다고 말합니다. 이 문제를 어떻게 해결할 수 있습니까?bs4로 phyton에서 텍스트를 긁어 모으는 법
코드의 구조를 (내가 BS4를 사용하고있어)이 같다 : 모든 사람에게
q=requests.get(url)
soup=BeautifulSoup(q.content, "html.parser")
x=soup.find("a", {"class":"comments"})
y=x.find_all("div", {"class":"blabla"})
i=0
for item in y:
name=str(i)
comment=item.find_all("p")
out_file=open('%s.txt'%CreatorName, "w")
out_file.write(str(comment)
out_file.close
i=i+1
감사합니다.
out_file = open ('% s.txt'% name, "w") – SerpeVerde