我做了一個簡單的Python腳本,這擦傷特定網站如何通過網頁抓取獲取表情符號?
下面是示例代碼
import requests
site='www.example.com'
f=open("text.txt","a")
page = requests.get(site)
contents = page.content
f.write(contents)
f.close()
之後,我過濾數據通過使用此代碼來從一個特定的標記一些文本(不但最好的方法)
words = []
f = open("text.txt", "r")
for line in f:
try:
if(line[0]=="<" and line[1]=="l" and line[2]=="i" and line[3]==">"):
words.append(line.decode('utf-8'))
except BaseException,e:
pass
for a in words:
print a.encode("utf-8")
雖然我成功地獲取所需的我的數據,但是當我嘗試獲取包含的表情符號的文本問題就出現了。
這裏是我的輸出
I am pretty happy ☺ coz i can easily recall this ☝stuff
#x1f60f;😏
一個片段,使任何想法如何將這個「#x1f60f」轉換成表情符號?
PS - 我想在火力拯救這件事很好,但它仍表現出這些「#x1f60f」那裏
使用解碼功能,看看這個【答案】(https://stackoverflow.com/questions/41604811/python-unicode-character-conversion-for-emoji#回答41605038) – 2017-09-27 08:18:35