爬取豆瓣各类电影前十名

'''
Request URL:https://movie.douban.com/j/chart/top_list?type=11&interval_id=100%3A90&action=&start=20&limit=20
type:11
interval_id:100:90
action:
start:20
limit:20
'''

from urllib import request
import json

# for i in range(28):
#     start = i * 20
#     base_url = 'https://movie.douban.com/j/chart/top_list?type=11&interval_id=100%3A90&action=&start='+str(start)+'&limit=20'
#
#     response = request.urlopen(base_url)
#
#     html = response.read()
#     html = html.decode('utf-8')
#     # html = html.split('},')
#     # json_data = json.loads(html)
#     print(html)

base_url = 'https://movie.douban.com/j/chart/top_list?type=13&interval_id=100%3A90&action=&start=0&limit=28'

response = request.urlopen(base_url)

html = response.read()
html = html.decode('utf-8')
print(type(html))

#json格式化能把上面的str数据类型改为可以迭代的list类型
json_data = json.loads(html)
print(type(json_data))
x = 1
for i in json_data:
    print(x,i['title'])
    x +=

 

posted @ 2018-03-10 21:35  Bob__Zhang  阅读(618)  评论(0编辑  收藏  举报