【发布时间】:2018-03-08 14:31:05
【问题描述】:
我做了一个简单的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")
虽然我成功获取了我想要的数据,但是当我尝试获取包含表情符号的文本时出现了问题。
这是我输出的一个 sn-p
I am pretty happy ☺ coz i can easily recall this ☝stuff
#x1f60f;😏
那么知道如何将这个“#x1f60f”转换为表情符号吗?
P.S - 我也在尝试将它保存在 firebase 中,但它仍然在上面显示这些“#x1f60f”
【问题讨论】:
-
使用解码功能,看看这个answer