寻求一些帮助。我正在研究一个项目,使用Python中的Beautiful Soup来抓取具体的Craigslist帖子。我可以成功显示在帖子标题中发现的emojis,但在帖子正文中未成功。我尝试了不同的变化,但迄今为止没有任何工作。任何帮助,将不胜感激。用美丽的汤编码Emojis
代码:从身体收到
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