movie_ids = []
for index in range(0,250,50):
response = urllib.urlopen('http://api.douban.com/v2/movie/top250?start=%d&count=50'%index)
data = response.read()
data_json = json.loads(data)
movies250 = data_json['subjects']
for movie in movies250:
movie_ids.append(movie['id'])
print movie['id'],movie['title']
time.sleep(3)
print ('250id获取完成')
for mid in movie_ids:
response = urllib.urlopen('http://api.douban.com/v2/movie/%s'%mid)
data = response.read()
data_json = json.loads(data)#数据整理并插入数据库
analysis(data_json, mid)
count_1 +=1
time.sleep(1.5)
db.close()# 关闭数据库连接
print ('查询了%d条'%count_1) 作者: super 时间: 2017-8-4 15:25
测试代码插入