PowerToys/Plugins/WinAlfred.Plugin.DouBan/main.py

25 lines
649 B
Python
Raw Normal View History

2013-12-23 15:53:38 +00:00
#encoding=utf8
import requests
from bs4 import BeautifulSoup
import json
2013-12-23 15:53:38 +00:00
class PyWinAlfred():
2013-12-23 15:53:38 +00:00
def query(self,key):
k = key.split(" ")[1]
2014-01-09 14:16:19 +00:00
if not k:
return ""
2013-12-23 15:53:38 +00:00
r = requests.get('http://movie.douban.com/subject_search?search_text=' + k)
bs = BeautifulSoup(r.text)
results = []
for i in bs.select(".article table .pl2 a"):
res = {}
t = i.text.strip().replace(" ","")
res["Title"] = t.replace("\\n","")
results.append(res)
return json.dumps(results)
2013-12-23 15:53:38 +00:00
if __name__ == "__main__":
p = PyWinAlfred()
print p.query("movie geo")