ヘルプを探しています。私はPythonで美しいスープを使って特定のCraigslist投稿を掻き集めるプロジェクトに取り組んでいます。投稿のタイトル内に見つかった絵文字を正常に表示できますが、投稿体内では失敗しています。私はさまざまなバリエーションを試しましたが、これまでのところ何も働いていません。どんな助けもありがとう。エモジスを美味しいスープでエンコードする
コード:
f = open("clcondensed.txt", "w")
html2 = requests.get("https://raleigh.craigslist.org/wan/6078682335.html")
soup = BeautifulSoup(html2.content,"html.parser")
#Post Title
title = soup.find(id="titletextonly")
title1 = soup.title.string.encode("ascii","xmlcharrefreplace")
f.write(title1)
#Post Body
body = soup.find(id="postingbody")
body = str(body)
body = body.encode("ascii","xmlcharrefreplace")
f.write(body)
エラーが身体から受け取っ:
'ascii' codec can't decode byte 0xef in position 273: ordinal not in range(128)
これに似ている可能性があります。http://stackoverflow.com/questions/9644099/python-ascii-codec-cant-decode-byte – anonyXmous