如何通过网页抓取获取表情符号?
问题描述:
我做了一个简单的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