I stumbled on the Hatena Keyword API. The script itself works fine, so I think it's okay if only Unicode processing works.
hatenaapi.py
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import xmlrpclib
import sys, codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
get_input = raw_input("prease keywords: ")
server = xmlrpclib.ServerProxy("http://d.hatena.ne.jp/xmlrpc")
res = server.hatena.getSimilarWord({"wordlist": get_input})
print res["wordlist"]
When I run it, it picks it up, but there is a problem with Unicode processing. Unicode appears as it is in the displayed character string.
Well, if you just pick up related keywords ... I realized that I was lacking in study, so I decided to write a memorandum.
*******************************************
For the time being, I thought that I could do something about Unicode escape, I saved it externally as txt and read it.
hatenaapi.py
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import xmlrpclib
import sys, codecs
sys.stdin = codecs.getreader("utf-8")(sys.stdin)
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
get_input = raw_input("prease keywords: ")
server = xmlrpclib.ServerProxy("http://d.hatena.ne.jp/xmlrpc")
res = server.hatena.getSimilarWord({"wordlist": get_input})
f = open("hatena.txt" , "aw")
lists = res["wordlist"]
for x in lists:
f.write(str(x) + "\n")
f.close
f = open("hatena.txt","rb")
data = f.read()
f.close()
print data.decode("unicode-escape")
Isn't it easier?
Recommended Posts