Skip to content

Commit

Permalink
爬取豆瓣前十页数据
Browse files Browse the repository at this point in the history
  • Loading branch information
JLUVicent committed Sep 14, 2021
1 parent 38ac7f1 commit d848ac6
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 0 deletions.
71 changes: 71 additions & 0 deletions 10_urllib_ajax的get请求豆瓣电影前10页.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 难点:找接口
# https://movie.douban.com/j/chart/top_list?type=24&interval_id=100%3A90&action=&
# start=0&limit=20
# https://movie.douban.com/j/chart/top_list?type=24&interval_id=100%3A90&action=&
# start=20&limit=20
# https://movie.douban.com/j/chart/top_list?type=24&interval_id=100%3A90&action=&
# start=40&limit=20
# https://movie.douban.com/j/chart/top_list?type=24&interval_id=100%3A90&action=&
# start=60&limit=20

# page 1 2 3 4
# start 0 20 40 60

#start (page-1)*20

# 下载豆瓣电影前十页的数据
# (1)请求对象的定制
# (2)获取响应的数据
# (3)下载数据
import urllib.parse
import urllib.request


def create_request(page):
# url1 = 'https://movie.douban.com/j/chart/top_list?type=24&interval_id=100%3A90&action=&start='
# page = str(page)
# url2 = '&limit=20'
# url = url1+page+url2
base_url = 'https://movie.douban.com/j/chart/top_list?type=24&interval_id=100%3A90&action=&'

data = {
'start': (page-1)*20,
'limit': 20
}

data = urllib.parse.urlencode(data)
url = base_url+data
# print(url)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36'
}

request = urllib.request.Request(url=url, headers=headers)

return request


def get_content(request):
response = urllib.request.urlopen(request)
content = response.read().decode('utf_8')
return content


def down_load(page, content):
with open('douban'+str(page)+'.json', 'w', encoding='utf-8') as fp:
fp.write(content)


# 程序入口
if __name__ == '__main__':
start_page = int(input('请输入起始页码:'))
end_page = int(input('请输入终止页码:'))

for page in range(start_page, end_page+1):
# print(page)
# 要求每一页都有自己请求对象的定制
request = create_request(page)
# (2)获取响应的数据
content = get_content(request)
# (3)下载数据
down_load(page, content)
1 change: 1 addition & 0 deletions douban10.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions douban2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"rating":["9.2","45"],"rank":21,"cover_url":"https://img9.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2506524685.jpg","is_playable":true,"id":"1293270","types":["剧情","喜剧","家庭"],"regions":["美国"],"title":"寻子遇仙记","url":"https:\/\/movie.douban.com\/subject\/1293270\/","release_date":"1921-02-06","actor_count":27,"vote_count":36108,"score":"9.2","actors":["查理·卓别林","卡尔米勒","艾德娜·珀薇安丝","杰基·库根","艾伯特·奥斯汀","Nellie Bly Baker","亨利·伯格曼","Edward Biby","B.F. Blinn","Kitty Bradbury","弗兰克·坎皮沃","Bliss Chevalier","Robert Dunbar","丽塔·格雷","Jules Hanft","Kathleen Kay","Raymond Lee","Clyde McAtee","Lew Parker","艾斯特·罗尔斯顿","Granville Redmond","查尔斯·赖斯纳","Edgar Sherrod","Arthur Thalasso","S.D. Wilcox","汤姆·威尔森","杰克·库根"],"is_watched":false},{"rating":["9.2","50"],"rank":22,"cover_url":"https://img2.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p1339915772.jpg","is_playable":true,"id":"1303418","types":["喜剧","战争"],"regions":["美国"],"title":"你逃我也逃","url":"https:\/\/movie.douban.com\/subject\/1303418\/","release_date":"1942-03-06","actor_count":36,"vote_count":33798,"score":"9.2","actors":["卡洛·朗白","杰克·本尼","罗伯特·斯塔克","菲利克斯·布雷萨特","莱昂内尔·阿特威尔","Adolf E. Licho","George Lynn","奥拉夫·许滕","约翰·凯洛格","Hans Schumm","Charles Irwin","西戈·鲁曼","拉斯·鲍威尔","Wolfgang Zilzer","Armand 'Curly' Wright","Henry Victor","罗兰德·瓦尔诺","Ernö Verebes","Otto Reichow","Gene Rizzi","哈利韦尔·霍布斯","查尔斯·霍尔顿","迈尔斯·曼德","John Meredith","Maurice Murphy","赫尔穆特·丹丁","斯坦利·里吉斯","弗兰克·雷歇尔","鲁道夫·安德斯","莱兰·霍奇森","Maude Eburne","汤姆·杜根","詹姆斯·芬利森","Leslie Denison","Alec Craig","Sven Hugo Borg"],"is_watched":false},{"rating":["9.2","50"],"rank":23,"cover_url":"https://img2.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p1959764913.jpg","is_playable":true,"id":"1299628","types":["喜剧","爱情"],"regions":["美国"],"title":"马戏团","url":"https:\/\/movie.douban.com\/subject\/1299628\/","release_date":"1928-01-06","actor_count":19,"vote_count":17147,"score":"9.2","actors":["阿尔·欧内斯特·加西亚","梅尔纳·肯尼迪","哈里·克罗克","George Davis","亨利·伯格曼","蒂尼·桑福德","约翰兰德","查理·卓别林","艾伯特·奥斯汀","斯坦利·布莱斯通","海尼·康克林","Toraichi Kono","贝蒂莫里西","L.J. O'Connor","杰克 P. 皮尔斯","Hugh Saxon","Armand Triller","吉恩·巴瑞","乔治·W·戴维斯"],"is_watched":false},{"rating":["9.2","45"],"rank":24,"cover_url":"https://img2.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2559163201.jpg","is_playable":false,"id":"1393471","types":["喜剧","动画"],"regions":["美国"],"title":"欢乐树的朋友们:第二发球","url":"https:\/\/movie.douban.com\/subject\/1393471\/","release_date":"2003","actor_count":3,"vote_count":4466,"score":"9.2","actors":["沃伦·格拉夫","Rhode Montijo","凯恩·纳瓦罗"],"is_watched":false},{"rating":["9.2","50"],"rank":25,"cover_url":"https://img2.doubanio.com\/view\/subject\/l\/public\/s1806711.jpg","is_playable":false,"id":"1393472","types":["喜剧","动画"],"regions":["美国"],"title":"欢乐树的朋友们:第三击","url":"https:\/\/movie.douban.com\/subject\/1393472\/","release_date":"2004-08-01","actor_count":5,"vote_count":3630,"score":"9.2","actors":["Liz Stuart","Ken Pontac","凯恩·纳瓦罗","沃伦·格拉夫","Rhode Montijo"],"is_watched":false},{"rating":["9.2","50"],"rank":26,"cover_url":"https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2298274199.jpg","is_playable":false,"id":"26691373","types":["喜剧"],"regions":["英国"],"title":"迪兰·莫兰:脱身","url":"https:\/\/movie.douban.com\/subject\/26691373\/","release_date":"2015-11-30","actor_count":1,"vote_count":1628,"score":"9.2","actors":["迪兰·莫兰"],"is_watched":false},{"rating":["9.2","50"],"rank":27,"cover_url":"https://img9.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2508661126.jpg","is_playable":false,"id":"4199429","types":["喜剧"],"regions":["美国"],"title":"乔治·卡林:你们都有病","url":"https:\/\/movie.douban.com\/subject\/4199429\/","release_date":"1999","actor_count":1,"vote_count":1294,"score":"9.2","actors":["乔治·卡林"],"is_watched":false},{"rating":["9.2","50"],"rank":28,"cover_url":"https://img2.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2579512501.jpg","is_playable":false,"id":"34937094","types":["喜剧"],"regions":["英国"],"title":"米兰达:我的欢乐庆典","url":"https:\/\/movie.douban.com\/subject\/34937094\/","release_date":"2020-01-01","actor_count":7,"vote_count":1034,"score":"9.2","actors":["米兰达·哈特","莎莉·菲利普斯","萨拉·哈德兰","派翠西亚·霍吉","汤姆·艾利斯","亚当·雷纳","多米尼克·科尔曼"],"is_watched":false},{"rating":["9.1","45"],"rank":29,"cover_url":"https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p501177648.jpg","is_playable":true,"id":"3319755","types":["剧情","喜剧","爱情"],"regions":["美国"],"title":"怦然心动","url":"https:\/\/movie.douban.com\/subject\/3319755\/","release_date":"2010-07-26","actor_count":32,"vote_count":1547789,"score":"9.1","actors":["玛德琳·卡罗尔","卡兰·麦克奥利菲","瑞贝卡·德·莫妮","安东尼·爱德华兹","约翰·马奥尼","佩内洛普·安·米勒","艾丹·奎因","凯文·韦斯曼","摩根·莉莉","瑞安·克茨纳","吉莉安·普法夫","迈克尔·博萨","博·勒纳","杰奎琳·埃沃拉","泰勒·格鲁秀斯","艾莉·布莱恩特","阿什莉·泰勒","伊瑟尔·布罗萨德","科迪·霍恩","迈克尔·博尔顿","肖恩·哈珀","斯戴芬妮·斯考特","帕特丽夏·伦茨","马修·戈尔德","阿罗拉·凯瑟琳·史密斯","凯莉·唐纳利","索菲亚·撒高","米歇尔·梅斯默","斯科特·乔尔·吉兹基","罗德·迈尔斯","卡拉 帕西托","凯特琳·帕西托"],"is_watched":false},{"rating":["9.1","45"],"rank":30,"cover_url":"https://img9.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2614500706.jpg","is_playable":true,"id":"20495023","types":["喜剧","动画","奇幻","音乐"],"regions":["美国"],"title":"寻梦环游记","url":"https:\/\/movie.douban.com\/subject\/20495023\/","release_date":"2017-11-24","actor_count":25,"vote_count":1362582,"score":"9.1","actors":["安东尼·冈萨雷斯","盖尔·加西亚·贝纳尔","本杰明·布拉特","阿兰娜·乌巴赫","芮妮·维克托","杰米·卡米尔","阿方索·阿雷奥","赫伯特·西古恩萨","加布里埃尔·伊格莱西亚斯","隆巴多·博伊尔","安娜·奥菲丽亚·莫吉亚","娜塔丽·科尔多瓦","赛琳娜·露娜","爱德华·詹姆斯·奥莫斯","索菲亚·伊斯皮诺萨","卡拉·梅迪纳","黛娅娜·欧特里","路易斯·瓦尔德斯","布兰卡·阿拉切利","萨尔瓦多·雷耶斯","切奇·马林","奥克塔维·索利斯","约翰·拉岑贝格","以利亚·罗德里格斯","石桥阳彩"],"is_watched":false},{"rating":["9.1","45"],"rank":31,"cover_url":"https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p792443418.jpg","is_playable":true,"id":"1293350","types":["剧情","喜剧","犯罪"],"regions":["英国"],"title":"两杆大烟枪","url":"https:\/\/movie.douban.com\/subject\/1293350\/","release_date":"1998-08-28","actor_count":23,"vote_count":512504,"score":"9.1","actors":["杰森·弗莱明","德克斯特·弗莱彻","尼克·莫兰","杰森·斯坦森","斯蒂文·麦金托什","斯汀","维尼·琼斯","弗兰克·哈珀","维克多·麦奎尔","安德鲁·蒂曼","马修·沃恩","杰克·亚伯拉罕","史蒂夫·斯威尼","薇拉·黛","罗尼·福克斯","丹尼·约翰-儒勒","阿兰·福德","罗伯·布莱顿","瓦斯·布莱克伍德","Lenny McLean","尼古拉斯·罗尔","P.H.莫里亚蒂","斯蒂芬·马库斯"],"is_watched":false},{"rating":["9.1","45"],"rank":32,"cover_url":"https://img9.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p1612355875.jpg","is_playable":true,"id":"1293460","types":["喜剧","歌舞","爱情"],"regions":["美国"],"title":"雨中曲","url":"https:\/\/movie.douban.com\/subject\/1293460\/","release_date":"1952-04-11","actor_count":53,"vote_count":177303,"score":"9.1","actors":["吉恩·凯利","唐纳德·奥康纳","黛比·雷诺斯","简·哈根","米勒德·米切尔","赛德·查里斯","达格拉斯·福雷","丽塔·莫雷诺","道恩·艾达丝","John Albright","Betty Allen","Bette Arlen","David Bair","玛格丽特·伯特","Madge Blake","Gail Bonney","Chet Brandenburg","梅·克拉克","Harry Cody","Chick Collins","Pat Conway","Jeanne Coyne","Fred Datig Jr.","凯·德利斯","John Dodsworth","金·多诺万","Phil Dunham","海伦·艾比罗克","Richard Emory","Tommy Farrell","Ernie Flatt","贝丝·弗劳尔斯","罗伯特·福捷","Dan Foster","Robert Foulk","Eric Freeman","凯瑟琳·弗里曼","兰斯·富勒","杰克·乔治","John George","Inez Gorman","A. Cameron Grant","Beatrice Gray","William Hamel","山姆·哈里斯","Timmy Hawkins","Jean Heremans","斯图尔特·霍姆斯","肯纳G.肯普","迈克·拉里","乔伊·兰辛","William F. Leicester","Sylvia Lewis"],"is_watched":false},{"rating":["9.1","45"],"rank":33,"cover_url":"https://img9.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p1960167314.jpg","is_playable":true,"id":"1295646","types":["喜剧","剧情","战争"],"regions":["美国"],"title":"大独裁者","url":"https:\/\/movie.douban.com\/subject\/1295646\/","release_date":"1940-10-15","actor_count":8,"vote_count":62989,"score":"9.1","actors":["查理·卓别林","宝莲·高黛","杰克·奥克","雷金纳德·加德纳","邱岳峰","卡特·德黑文","比利·吉尔伯特","格蕾斯·海尔"],"is_watched":false},{"rating":["9.1","45"],"rank":34,"cover_url":"https://img2.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2248676081.jpg","is_playable":true,"id":"1292778","types":["剧情","喜剧","动作","战争","冒险"],"regions":["美国"],"title":"将军号","url":"https:\/\/movie.douban.com\/subject\/1292778\/","release_date":"1926-12-25","actor_count":12,"vote_count":21633,"score":"9.1","actors":["巴斯特·基顿","玛丽昂·马克","格伦·卡文德","吉姆·法利","弗雷德里克·弗鲁姆","查尔斯·亨利·史密斯","弗兰克·巴恩斯","乔·基顿","麦克·多林","汤姆·纳恩","波利斯·卡洛夫","安东尼·哈维"],"is_watched":false},{"rating":["9.1","45"],"rank":35,"cover_url":"https://img9.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2652268085.jpg","is_playable":false,"id":"35472124","types":["剧情","喜剧","同性"],"regions":["泰国"],"title":"普吉岛的最后黄昏","url":"https:\/\/movie.douban.com\/subject\/35472124\/","release_date":"2021-05-20","actor_count":2,"vote_count":12833,"score":"9.1","actors":["普提蓬·阿萨拉塔纳功","克里特·安努艾德奇康"],"is_watched":false},{"rating":["9.1","45"],"rank":36,"cover_url":"https://img9.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2384320756.jpg","is_playable":false,"id":"1303525","types":["喜剧","犯罪","剧情","奇幻"],"regions":["意大利","英国","南斯拉夫"],"title":"流浪者之歌","url":"https:\/\/movie.douban.com\/subject\/1303525\/","release_date":"1988-12-21","actor_count":15,"vote_count":9862,"score":"9.1","actors":["达沃尔·杜伊莫维奇","博拉·托德洛维奇","Ajnur Redzepi","Mirsad Zulic","Suada Karisik","Elvira Sali","Husnija Hasimovic","扎比特·梅梅托夫","鲁比卡·艾德维奇","Sinolicka Trpkova","Boris Juh","普雷德拉格·拉科维奇","Marjeta Gregorac","布兰科·德约里奇","Sedrije Halim"],"is_watched":false},{"rating":["9.1","45"],"rank":37,"cover_url":"https://img2.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2533709702.jpg","is_playable":false,"id":"4181031","types":["动画","喜剧"],"regions":["美国"],"title":"欢乐树的朋友们","url":"https:\/\/movie.douban.com\/subject\/4181031\/","release_date":"2006-05-03","actor_count":3,"vote_count":6319,"score":"9.1","actors":["沃伦·格拉夫","凯恩·纳瓦罗","Rhode Montijo"],"is_watched":false},{"rating":["9.1","45"],"rank":38,"cover_url":"https://img2.doubanio.com\/view\/subject\/l\/public\/s1806732.jpg","is_playable":false,"id":"3075070","types":["动画","喜剧"],"regions":["美国"],"title":"欢乐树的朋友们:赶尽杀绝","url":"https:\/\/movie.douban.com\/subject\/3075070\/","release_date":"2005-11-28","actor_count":3,"vote_count":5450,"score":"9.1","actors":["Ken Pontac","沃伦·格拉夫","凯恩·纳瓦罗"],"is_watched":false},{"rating":["9.1","45"],"rank":39,"cover_url":"https://img3.doubanio.com\/view\/subject\/l\/public\/s3622650.jpg","is_playable":false,"id":"3075092","types":["喜剧","动画"],"regions":["美国"],"title":"欢乐树的朋友们:滑雪巡逻救生队","url":"https:\/\/movie.douban.com\/subject\/3075092\/","release_date":"2006-04-12","actor_count":3,"vote_count":1678,"score":"9.1","actors":["沃伦·格拉夫","比利·维斯特","凯恩·纳瓦罗"],"is_watched":false},{"rating":["9.1","45"],"rank":40,"cover_url":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2517976810.jpg","is_playable":false,"id":"4850732","types":["喜剧"],"regions":["英国","澳大利亚"],"title":"迪兰·莫兰:是什么?","url":"https:\/\/movie.douban.com\/subject\/4850732\/","release_date":"2009","actor_count":1,"vote_count":1247,"score":"9.1","actors":["迪兰·莫兰"],"is_watched":false}]
1 change: 1 addition & 0 deletions douban3.json

Large diffs are not rendered by default.

Loading

0 comments on commit d848ac6

Please sign in to comment.