Python实现的豆瓣电影信息查询
Python #小偷2012-11-25 22:32
实现的代码如下:
# -*- coding: utf-8 -*- import urllib,re,json #movie: #search engine:http://movie.douban.com/subject_search?search_text=+film_name+&cat=1002 #info:https://api.douban.com/v2/movie/:id print("please input the name of film u want to search:") film_name = raw_input() movie_search_engine = "http://movie.douban.com/subject_search?search_text="+film_name+"&cat=1002" movie_search = movie_search_engine html = urllib.urlopen(movie_search).read() match = re.findall('<a class="nbg" href="(.+?)" >',html) match = match[0] movie_id = re.split(r'\D+',match) movie_id = movie_id[1] movie_url = "https://api.douban.com/v2/movie/"+movie_id movie_url = urllib.urlopen(movie_url).read() jsondata = json.loads(movie_url) name = jsondata["alt_title"] rate = jsondata["rating"]["average"] director = jsondata["attrs"]["director"][0] cast = jsondata["attrs"]["cast"] pubdate = jsondata["attrs"]["pubdate"][0] movie_duration = jsondata["attrs"]["movie_duration"][0] country = jsondata["attrs"]["country"][0] movie_type = jsondata["attrs"]["movie_type"] print("name:" + name) print("rate:" + rate) print("director:" + director) print("casts:" + cast[0] +"\\"+ cast[1] +"\\"+ cast[2]) print("country:" + country) print("duration:" + movie_duration) print("pubdate:" + pubdate) print("country:" + movie_type[0] +"\\"+ movie_type[1] +"\\"+ movie_type[2]) print("--------------------------------------------------------By http://yige.org")
相关文章
- Python实现双倍超立方数 2012/11/25
- 用Python实现定时关机 2012/11/25
- 用Python实现的简易采集爬虫 2012/11/23
- Python实现QQ登陆 2012/11/23
- 用Python按日期导出所有微信 2012/11/23
- Python使用global语句 2012/11/23
- 说说Python的版本选择、IDE、库 2012/11/23
- Python实现的记事本尾巴(仿QQ尾巴) 2012/11/23
- python写的http客户端测试程序 2012/11/23
- 用python下载网页 2012/11/23