网络爬虫笔记【4】 掌握获取 Ajax 异步加载网页内容的方法

AJAX(Asynchronous Javascript and XML,异步的 Javascript 和 XML)。AJAX 最大的优点是在不重新加载整个页面的情况下,可以与服务器交换数据并更新部分网页的内容。

我们以 豆瓣电影 为例,打开网页之后,按 F12 ,在 Network 中监控一下这个页面。通过测试可以发现,每点击一次“加载更多”按钮,便会多一个响应:

https://movie.douban.com/j/new_search_subjects?sort=U&range=0,10&tags=&start=20
https://movie.douban.com/j/new_search_subjects?sort=U&range=0,10&tags=&start=40
https://movie.douban.com/j/new_search_subjects?sort=U&range=0,10&tags=&start=60
......

我们将其放入浏览器中直接打开,可以看到它以 json 的格式记录了新加载的电影信息。而且观察这些 url 的格式,发现了没?它们前面都长一样,唯一的不同就是最后的 “start = ”不一样,而且每一个相差都是20,你说巧不巧,每次点击加载更多后刷新出来的电影也是20个,放浏览器中直接打开后看到的 json 里包含的也是20个电影信息,这说明了什么就不用我说了吧。

搞清楚了这一点,剩下的工作就简单了,下面我们开始尝试一下。

# 抓取 ajax 页面
# demo 1 

import urllib.request
import urllib.parse
import urllib.error

# https://movie.douban.com/j/new_search_subjects?sort=U&range=0,10&tags=&start=20

url = 'https://movie.douban.com/j/new_search_subjects?'
params = {'sort':'U', 'range':'0,10', 'tags':'', 'start':'20'}
params_encode = urllib.parse.urlencode(params).encode('utf-8')
headers = {
        'Accept': 'text/html',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
}

try:
    request = urllib.request.Request(url, data=params_encode, headers=headers)
    with urllib.request.urlopen(request) as response:
        print(response.read().decode('utf-8'))
except urllib.error.HTTPError as e:
    print(e)
except urllib.error.URLError as e:
    print(e)

运行结果:

{"data":[{"directors":["涅提·蒂瓦里"],"rate":"9.1","cover_x":4500,"star":"45","title":"摔跤吧!爸爸","url":"https:\/\/movie.douban.com\/subject\/26387939\/","casts":["阿米尔·汗","法缇玛·萨那·纱卡","桑亚·玛荷塔","阿帕尔夏克提·库拉那","沙克希·坦沃"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2457983084.jpg","id":"26387939","cover_y":6300},{"directors":["史蒂文·斯皮尔伯格"],"rate":"8.7","cover_x":2000,"star":"45","title":"头号玩家","url":"https:\/\/movie.douban.com\/subject\/4920389\/","casts":["泰伊·谢里丹","奥利维亚·库克","本·门德尔森","马克·里朗斯","丽娜·维特"],"cover":"https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2516578307.jpg","id":"4920389","cover_y":3000},{"directors":["金磊"],"rate":"6.2","cover_x":690,"star":"30","title":"中国好声音 第五季","url":"https:\/\/movie.douban.com\/subject\/27187829\/","casts":["周杰伦","庾澄庆","谢霆锋","李健"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2527870040.jpg","id":"27187829","cover_y":1076},{"directors":["苏珊娜·福格尔"],"rate":"6.6","cover_x":1038,"star":"35","title":"我的间谍前男友","url":"https:\/\/movie.douban.com\/subject\/26999424\/","casts":["米拉·库尼斯","凯特·麦克金农","贾斯汀·塞洛克斯","萨姆·修汉","薇尔玛·斯泽克斯"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2533822396.jpg","id":"26999424","cover_y":1600},{"directors":["林超贤"],"rate":"8.3","cover_x":1429,"star":"40","title":"红海行动","url":"https:\/\/movie.douban.com\/subject\/26861685\/","casts":["张译","黄景瑜","海清","杜江","蒋璐霞"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2514119443.jpg","id":"26861685","cover_y":2000},{"directors":["姜文"],"rate":"7.2","cover_x":2048,"star":"35","title":"邪不压正","url":"https:\/\/movie.douban.com\/subject\/26366496\/","casts":["彭于晏","廖凡","姜文","周韵","许晴"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2526297221.jpg","id":"26366496","cover_y":2867},{"directors":["弗兰克·德拉邦特"],"rate":"9.6","cover_x":2000,"star":"50","title":"肖申克的救赎","url":"https:\/\/movie.douban.com\/subject\/1292052\/","casts":["蒂姆·罗宾斯","摩根·弗里曼","鲍勃·冈顿","威廉姆·赛德勒","克兰西·布朗"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p480747492.jpg","id":"1292052","cover_y":2963},{"directors":["乔·德特杜巴"],"rate":"5.9","cover_x":1000,"star":"30","title":"巨齿鲨","url":"https:\/\/movie.douban.com\/subject\/26426194\/","casts":["杰森·斯坦森","李冰冰","雷恩·威尔森","鲁比·罗丝","赵文瑄"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2530572643.jpg","id":"26426194","cover_y":1399},{"directors":["新海诚"],"rate":"8.4","cover_x":1428,"star":"40","title":"你的名字。","url":"https:\/\/movie.douban.com\/subject\/26683290\/","casts":["神木隆之介","上白石萌音","长泽雅美","市原悦子","成田凌"],"cover":"https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2395733377.jpg","id":"26683290","cover_y":2000},{"directors":["拉吉库马尔·希拉尼"],"rate":"9.2","cover_x":3030,"star":"45","title":"三傻大闹宝莱坞","url":"https:\/\/movie.douban.com\/subject\/3793023\/","casts":["阿米尔·汗","卡琳娜·卡普尔","马达范","沙尔曼·乔希","奥米·瓦依达"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p579729551.jpg","id":"3793023","cover_y":4364},{"directors":["吴京"],"rate":"7.1","cover_x":1024,"star":"35","title":"战狼2","url":"https:\/\/movie.douban.com\/subject\/26363254\/","casts":["吴京","弗兰克·格里罗","吴刚","张翰","卢靖姗"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2494701965.jpg","id":"26363254","cover_y":1548},{"directors":["姜文"],"rate":"8.7","cover_x":1500,"star":"45","title":"让子弹飞","url":"https:\/\/movie.douban.com\/subject\/3742360\/","casts":["姜文","葛优","周润发","刘嘉玲","陈坤"],"cover":"https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p1512562287.jpg","id":"3742360","cover_y":2200},{"directors":["李安"],"rate":"9.0","cover_x":3375,"star":"45","title":"少年派的奇幻漂流","url":"https:\/\/movie.douban.com\/subject\/1929463\/","casts":["苏拉·沙玛","伊尔凡·可汗","拉菲·斯波","阿迪勒·侯赛因","塔布"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p1784592701.jpg","id":"1929463","cover_y":5000},{"directors":["普特鹏·普罗萨卡·那·萨克那卡林","华森·波克彭"],"rate":"8.3","cover_x":1280,"star":"40","title":"初恋这件小事","url":"https:\/\/movie.douban.com\/subject\/4739952\/","casts":["平采娜·乐维瑟派布恩","马里奥·毛瑞尔","苏达拉·布查蓬","雅尼卡·桑普蕾舞","诺特·阿查拉那·阿瑞亚卫考"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p1505312273.jpg","id":"4739952","cover_y":1829},{"directors":["詹姆斯·卡梅隆"],"rate":"8.6","cover_x":800,"star":"45","title":"阿凡达","url":"https:\/\/movie.douban.com\/subject\/1652587\/","casts":["萨姆·沃辛顿","佐伊·索尔达娜","西格妮·韦弗","史蒂芬·朗","米歇尔·罗德里格兹"],"cover":"https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p492458287.jpg","id":"1652587","cover_y":1185},{"directors":["彼得·威尔"],"rate":"9.2","cover_x":997,"star":"45","title":"楚门的世界","url":"https:\/\/movie.douban.com\/subject\/1292064\/","casts":["金·凯瑞","劳拉·琳妮","艾德·哈里斯","诺亚·艾默里奇","娜塔莎·麦克艾霍恩"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p479682972.jpg","id":"1292064","cover_y":1500},{"directors":["吕克·贝松"],"rate":"9.4","cover_x":658,"star":"45","title":"这个杀手不太冷","url":"https:\/\/movie.douban.com\/subject\/1295644\/","casts":["让·雷诺","娜塔莉·波特曼","加里·奥德曼","丹尼·爱罗","彼得·阿佩尔"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p511118051.jpg","id":"1295644","cover_y":980},{"directors":["沈严","刘海波"],"rate":"8.2","cover_x":2126,"star":"40","title":"天盛长歌","url":"https:\/\/movie.douban.com\/subject\/26761328\/","casts":["陈坤","倪妮","赵立新","倪大红","袁弘"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2530496815.jpg","id":"26761328","cover_y":2976},{"directors":["克里斯托弗·诺兰"],"rate":"9.2","cover_x":4858,"star":"45","title":"星际穿越","url":"https:\/\/movie.douban.com\/subject\/1889243\/","casts":["马修·麦康纳","安妮·海瑟薇","杰西卡·查斯坦","卡西·阿弗莱克","迈克尔·凯恩"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2206088801.jpg","id":"1889243","cover_y":7200},{"directors":["刘伟强","麦兆辉"],"rate":"9.1","cover_x":580,"star":"45","title":"无间道","url":"https:\/\/movie.douban.com\/subject\/1307914\/","casts":["刘德华","梁朝伟","黄秋生","曾志伟","郑秀文"],"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2233971046.jpg","id":"1307914","cover_y":879}]}
# 抓取 ajax 页面
# demo 2

import urllib.request
import urllib.parse
import urllib.error
import json

# https://movie.douban.com/j/new_search_subjects?sort=U&range=0,10&tags=&start=20

url = 'https://movie.douban.com/j/new_search_subjects?'
params = {'sort':'U', 'range':'0,10', 'tags':'', 'start':'20'}
params_encode = urllib.parse.urlencode(params).encode('utf-8')
headers = {
        'Accept': 'text/html',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
}

try:
    request = urllib.request.Request(url, data=params_encode, headers=headers)
    with urllib.request.urlopen(request) as response:
        # 原来的方法得到编码后数据,因为 json 将其当作字符串,用引号包围起来了
        #print(response.read().decode('utf-8'))
        
        # 可以查看响应头,有 Content-Type: application/json; charset=utf-8
        #print(response.headers)
        
        print(json.loads(response.read().decode('utf-8')))
except urllib.error.HTTPError as e:
    print(e)
except urllib.error.URLError as e:
    print(e)

运行结果:

{'data': [{'casts': ['阿米尔·汗', '法缇玛·萨那·纱卡', '桑亚·玛荷塔', '阿帕尔夏克提·库拉那', '沙克希·坦沃'], 'cover_y': 6300, 'rate': '9.1', 'url': 'https://movie.douban.com/subject/26387939/', 'title': '摔跤吧!爸爸', 'star': '45', 'directors': ['涅提·蒂瓦里'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2457983084.jpg', 'cover_x': 4500, 'id': '26387939'}, {'casts': ['泰伊·谢里丹', '奥利维亚·库克', '本·门德尔森', '马克·里朗斯', '丽娜·维特'], 'cover_y': 3000, 'rate': '8.7', 'url': 'https://movie.douban.com/subject/4920389/', 'title': '头号玩家', 'star': '45', 'directors': ['史蒂文·斯皮尔伯格'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2516578307.jpg', 'cover_x': 2000, 'id': '4920389'}, {'casts': ['周杰伦', '庾澄庆', '谢霆锋', '李健'], 'cover_y': 1076, 'rate': '6.2', 'url': 'https://movie.douban.com/subject/27187829/', 'title': '中国好声音 第五季', 'star': '30', 'directors': ['金磊'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2527870040.jpg', 'cover_x': 690, 'id': '27187829'}, {'casts': ['米拉·库尼斯', '凯特·麦克金农', '贾斯汀·塞洛克斯', '萨姆·修汉', '薇尔玛·斯泽克斯'], 'cover_y': 1600, 'rate': '6.5', 'url': 'https://movie.douban.com/subject/26999424/', 'title': '我的间谍前男友', 'star': '35', 'directors': ['苏珊娜·福格尔'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2533822396.jpg', 'cover_x': 1038, 'id': '26999424'}, {'casts': ['张译', '黄景瑜', '海清', '杜江', '蒋璐霞'], 'cover_y': 2000, 'rate': '8.3', 'url': 'https://movie.douban.com/subject/26861685/', 'title': '红海行动', 'star': '40', 'directors': ['林超贤'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2514119443.jpg', 'cover_x': 1429, 'id': '26861685'}, {'casts': ['彭于晏', '廖凡', '姜文', '周韵', '许晴'], 'cover_y': 2867, 'rate': '7.2', 'url': 'https://movie.douban.com/subject/26366496/', 'title': '邪不压正', 'star': '35', 'directors': ['姜文'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2526297221.jpg', 'cover_x': 2048, 'id': '26366496'}, {'casts': ['蒂姆·罗宾斯', '摩根·弗里曼', '鲍勃·冈顿', '威廉姆·赛德勒', '克兰西·布朗'], 'cover_y': 2963, 'rate': '9.6', 'url': 'https://movie.douban.com/subject/1292052/', 'title': '肖申克的救赎', 'star': '50', 'directors': ['弗兰克·德拉邦特'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p480747492.jpg', 'cover_x': 2000, 'id': '1292052'}, {'casts': ['杰森·斯坦森', '李冰冰', '雷恩·威尔森', '鲁比·罗丝', '赵文瑄'], 'cover_y': 1399, 'rate': '5.9', 'url': 'https://movie.douban.com/subject/26426194/', 'title': '巨齿鲨', 'star': '30', 'directors': ['乔·德特杜巴'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2530572643.jpg', 'cover_x': 1000, 'id': '26426194'}, {'casts': ['神木隆之介', '上白石萌音', '长泽雅美', '市原悦子', '成田凌'], 'cover_y': 2000, 'rate': '8.4', 'url': 'https://movie.douban.com/subject/26683290/', 'title': '你的名字。', 'star': '40', 'directors': ['新海诚'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2395733377.jpg', 'cover_x': 1428, 'id': '26683290'}, {'casts': ['阿米尔·汗', '卡琳娜·卡普尔', '马达范', '沙尔曼·乔希', '奥米·瓦依达'], 'cover_y': 4364, 'rate': '9.2', 'url': 'https://movie.douban.com/subject/3793023/', 'title': '三傻大闹宝莱坞', 'star': '45', 'directors': ['拉吉库马尔·希拉尼'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p579729551.jpg', 'cover_x': 3030, 'id': '3793023'}, {'casts': ['吴京', '弗兰克·格里罗', '吴刚', '张翰', '卢靖姗'], 'cover_y': 1548, 'rate': '7.1', 'url': 'https://movie.douban.com/subject/26363254/', 'title': '战狼2', 'star': '35', 'directors': ['吴京'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2494701965.jpg', 'cover_x': 1024, 'id': '26363254'}, {'casts': ['姜文', '葛优', '周润发', '刘嘉玲', '陈坤'], 'cover_y': 2200, 'rate': '8.7', 'url': 'https://movie.douban.com/subject/3742360/', 'title': '让子弹飞', 'star': '45', 'directors': ['姜文'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p1512562287.jpg', 'cover_x': 1500, 'id': '3742360'}, {'casts': ['苏拉·沙玛', '伊尔凡·可汗', '拉菲·斯波', '阿迪勒·侯赛因', '塔布'], 'cover_y': 5000, 'rate': '9.0', 'url': 'https://movie.douban.com/subject/1929463/', 'title': '少年派的奇幻漂流', 'star': '45', 'directors': ['李安'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p1784592701.jpg', 'cover_x': 3375, 'id': '1929463'}, {'casts': ['平采娜·乐维瑟派布恩', '马里奥·毛瑞尔', '苏达拉·布查蓬', '雅尼卡·桑普蕾舞', '诺特·阿查拉那·阿瑞亚卫考'], 'cover_y': 1829, 'rate': '8.3', 'url': 'https://movie.douban.com/subject/4739952/', 'title': '初恋这件小事', 'star': '40', 'directors': ['普特鹏·普罗萨卡·那·萨克那卡林', '华森·波克彭'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p1505312273.jpg', 'cover_x': 1280, 'id': '4739952'}, {'casts': ['萨姆·沃辛顿', '佐伊·索尔达娜', '西格妮·韦弗', '史蒂芬·朗', '米歇尔·罗德里格兹'], 'cover_y': 1185, 'rate': '8.6', 'url': 'https://movie.douban.com/subject/1652587/', 'title': '阿凡达', 'star': '45', 'directors': ['詹姆斯·卡梅隆'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p492458287.jpg', 'cover_x': 800, 'id': '1652587'}, {'casts': ['金·凯瑞', '劳拉·琳妮', '艾德·哈里斯', '诺亚·艾默里奇', '娜塔莎·麦克艾霍恩'], 'cover_y': 1500, 'rate': '9.2', 'url': 'https://movie.douban.com/subject/1292064/', 'title': '楚门的世界', 'star': '45', 'directors': ['彼得·威尔'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p479682972.jpg', 'cover_x': 997, 'id': '1292064'}, {'casts': ['让·雷诺', '娜塔莉·波特曼', '加里·奥德曼', '丹尼·爱罗', '彼得·阿佩尔'], 'cover_y': 980, 'rate': '9.4', 'url': 'https://movie.douban.com/subject/1295644/', 'title': '这个杀手不太冷', 'star': '45', 'directors': ['吕克·贝松'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p511118051.jpg', 'cover_x': 658, 'id': '1295644'}, {'casts': ['陈坤', '倪妮', '赵立新', '倪大红', '袁弘'], 'cover_y': 2976, 'rate': '8.2', 'url': 'https://movie.douban.com/subject/26761328/', 'title': '天盛长歌', 'star': '40', 'directors': ['沈严', '刘海波'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2530496815.jpg', 'cover_x': 2126, 'id': '26761328'}, {'casts': ['马修·麦康纳', '安妮·海瑟薇', '杰西卡·查斯坦', '卡西·阿弗莱克', '迈克尔·凯恩'], 'cover_y': 7200, 'rate': '9.2', 'url': 'https://movie.douban.com/subject/1889243/', 'title': '星际穿越', 'star': '45', 'directors': ['克里斯托弗·诺兰'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2206088801.jpg', 'cover_x': 4858, 'id': '1889243'}, {'casts': ['刘德华', '梁朝伟', '黄秋生', '曾志伟', '郑秀文'], 'cover_y': 879, 'rate': '9.1', 'url': 'https://movie.douban.com/subject/1307914/', 'title': '无间道', 'star': '45', 'directors': ['刘伟强', '麦兆辉'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2233971046.jpg', 'cover_x': 580, 'id': '1307914'}]}
# 抓取 ajax 页面
# demo 3

import urllib.request
import urllib.parse
import urllib.error
import json

url = 'https://movie.douban.com/j/new_search_subjects?'
headers = {
        'Accept': 'text/html',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
}

# 循环次数自己设置,这里循环三次,爬取前60个电影数据
for p in range(0,3):
    page = p * 20
    params = {'sort':'U', 'range':'0,10', 'tags':'', 'start':str(page)}
    params_encode = urllib.parse.urlencode(params).encode('utf-8')
    
    try:
        request = urllib.request.Request(url, data=params_encode, headers=headers)
        with urllib.request.urlopen(request) as response:
            print(json.loads(response.read().decode('utf-8')))
            print('---'*20)
            
    except urllib.error.HTTPError as e:
        print(e)
    except urllib.error.URLError as e:
        print(e)

运行结果:

{'data': [{'casts': ['徐峥', '王传君', '周一围', '谭卓', '章宇'], 'cover_y': 1512, 'rate': '9.0', 'url': 'https://movie.douban.com/subject/26752088/', 'title': '我不是药神', 'star': '45', 'directors': ['文牧野'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2519070834.jpg', 'cover_x': 1080, 'id': '26752088'}, {'casts': ['周润发', '郭富城', '张静初', '冯文娟', '廖启智'], 'cover_y': 1000, 'rate': '8.1', 'url': 'https://movie.douban.com/subject/26425063/', 'title': '无双', 'star': '40', 'directors': ['庄文强'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2535096871.jpg', 'cover_x': 714, 'id': '26425063'}, {'casts': ['邓超', '孙俪', '郑恺', '王千源', '王景春'], 'cover_y': 5788, 'rate': '7.4', 'url': 'https://movie.douban.com/subject/4864908/', 'title': '影', 'star': '35', 'directors': ['张艺谋'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2530513100.jpg', 'cover_x': 3927, 'id': '4864908'}, {'casts': ['沈腾', '宋芸桦', '张一鸣', '张晨光', '常远'], 'cover_y': 950, 'rate': '6.7', 'url': 'https://movie.douban.com/subject/27605698/', 'title': '西虹市首富', 'star': '35', 'directors': ['闫非', '彭大魔'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2529206747.jpg', 'cover_x': 679, 'id': '27605698'}, {'casts': ['黄才伦', '艾伦', '宋阳', '卢靖姗', '沈腾'], 'cover_y': 8268, 'rate': '5.1', 'url': 'https://movie.douban.com/subject/27092785/', 'title': '李茶的姑妈', 'star': '25', 'directors': ['吴昱翰'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2533384240.jpg', 'cover_x': 5906, 'id': '27092785'}, {'casts': ['李易峰', '迈克尔·道格拉斯', '周冬雨', '曹炳琨', '王戈'], 'cover_y': 4181, 'rate': '7.3', 'url': 'https://movie.douban.com/subject/26925317/', 'title': '动物世界', 'star': '35', 'directors': ['韩延'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2525528688.jpg', 'cover_x': 2999, 'id': '26925317'}, {'casts': ['秦岚', '聂远', '佘诗曼', '吴谨言', '许凯'], 'cover_y': 1260, 'rate': '7.2', 'url': 'https://movie.douban.com/subject/26999852/', 'title': '延禧攻略', 'star': '35', 'directors': ['惠楷栋', '温德光'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2509891341.jpg', 'cover_x': 900, 'id': '26999852'}, {'casts': ['小罗伯特·唐尼', '克里斯·海姆斯沃斯', '克里斯·埃文斯', '马克·鲁弗洛', '乔什·布洛林'], 'cover_y': 2756, 'rate': '8.1', 'url': 'https://movie.douban.com/subject/24773958/', 'title': '复仇者联盟3:无限战争', 'star': '40', 'directors': ['安东尼·罗素', '乔·罗素'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2517753454.jpg', 'cover_x': 1968, 'id': '24773958'}, {'casts': ['雷佳音', '佟丽娅', '张衣', '于和伟', '王正佳'], 'cover_y': 2800, 'rate': '6.9', 'url': 'https://movie.douban.com/subject/27133303/', 'title': '超时空同居', 'star': '35', 'directors': ['苏伦'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2520331478.jpg', 'cover_x': 2000, 'id': '27133303'}, {'casts': ['杨紫', '邓伦', '陈钰琪', '罗云熙', '王一菲'], 'cover_y': 950, 'rate': '7.7', 'url': 'https://movie.douban.com/subject/26920281/', 'title': '香蜜沉沉烬如霜', 'star': '40', 'directors': ['朱锐斌', '李秉光', '澄丰'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2512135753.jpg', 'cover_x': 619, 'id': '26920281'}, {'casts': ['汤姆·克鲁斯', '亨利·卡维尔', '文·瑞姆斯', '西蒙·佩吉', '丽贝卡·弗格森'], 'cover_y': 3034, 'rate': '8.2', 'url': 'https://movie.douban.com/subject/26336252/', 'title': '碟中谍6:全面瓦解', 'star': '40', 'directors': ['克里斯托弗·麦奎里'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2529365085.jpg', 'cover_x': 2048, 'id': '26336252'}, {'casts': ['姚晨', '马伊琍', '袁文康', '吴昊宸', '王梓尘'], 'cover_y': 1600, 'rate': '7.4', 'url': 'https://movie.douban.com/subject/27140071/', 'title': '找到你', 'star': '35', 'directors': ['吕乐'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2534471408.jpg', 'cover_x': 1144, 'id': '27140071'}, {'casts': ['赵涛', '廖凡', '徐峥', '梁嘉艳', '刁亦男'], 'cover_y': 1600, 'rate': '7.7', 'url': 'https://movie.douban.com/subject/26972258/', 'title': '江湖儿女', 'star': '40', 'directors': ['贾樟柯'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2533283770.jpg', 'cover_x': 1142, 'id': '26972258'}, {'casts': ['保罗·路德', '伊万杰琳·莉莉', '迈克尔·佩纳', '汉娜·乔恩-卡门', '沃尔顿·戈金斯'], 'cover_y': 2756, 'rate': '7.4', 'url': 'https://movie.douban.com/subject/26636712/', 'title': '蚁人2:黄蜂女现身', 'star': '35', 'directors': ['佩顿·里德'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2529389608.jpg', 'cover_x': 1968, 'id': '26636712'}, {'casts': ['黄渤', '舒淇', '王宝强', '张艺兴', '于和伟'], 'cover_y': 1512, 'rate': '7.2', 'url': 'https://movie.douban.com/subject/26985127/', 'title': '一出好戏', 'star': '35', 'directors': ['黄渤'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2529571873.jpg', 'cover_x': 1080, 'id': '26985127'}, {'casts': ['莱昂纳多·迪卡普里奥', '约瑟夫·高登-莱维特', '艾伦·佩吉', '汤姆·哈迪', '渡边谦'], 'cover_y': 3300, 'rate': '9.3', 'url': 'https://movie.douban.com/subject/3541415/', 'title': '盗梦空间', 'star': '45', 'directors': ['克里斯托弗·诺兰'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p513344864.jpg', 'cover_x': 2229, 'id': '3541415'}, {'casts': ['张国荣', '张丰毅', '巩俐', '葛优', '英达'], 'cover_y': 732, 'rate': '9.6', 'url': 'https://movie.douban.com/subject/1291546/', 'title': '霸王别姬', 'star': '50', 'directors': ['陈凯歌'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p1910813120.jpg', 'cover_x': 494, 'id': '1291546'}, {'casts': ['理查·基尔', '萨拉·罗默尔', '琼·艾伦', '罗比·萨布莱特', '艾瑞克·阿瓦利'], 'cover_y': 2028, 'rate': '9.3', 'url': 'https://movie.douban.com/subject/3011091/', 'title': '忠犬八公的故事', 'star': '45', 'directors': ['拉斯·霍尔斯道姆'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p524964016.jpg', 'cover_x': 1433, 'id': '3011091'}, {'casts': ['小罗伯特·唐尼', '克里斯·埃文斯', '斯嘉丽·约翰逊', '克里斯·海姆斯沃斯', '杰瑞米·雷纳'], 'cover_y': 6565, 'rate': '8.1', 'url': 'https://movie.douban.com/subject/1866479/', 'title': '复仇者联盟', 'star': '40', 'directors': ['乔斯·韦登'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p1524904031.jpg', 'cover_x': 4724, 'id': '1866479'}, {'casts': ['汤姆·汉克斯', '罗宾·怀特', '加里·西尼斯', '麦凯尔泰·威廉逊', '莎莉·菲尔德'], 'cover_y': 1035, 'rate': '9.4', 'url': 'https://movie.douban.com/subject/1292720/', 'title': '阿甘正传', 'star': '45', 'directors': ['罗伯特·泽米吉斯'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p510876377.jpg', 'cover_x': 721, 'id': '1292720'}]}
------------------------------------------------------------
{'data': [{'casts': ['阿米尔·汗', '法缇玛·萨那·纱卡', '桑亚·玛荷塔', '阿帕尔夏克提·库拉那', '沙克希·坦沃'], 'cover_y': 6300, 'rate': '9.1', 'url': 'https://movie.douban.com/subject/26387939/', 'title': '摔跤吧!爸爸', 'star': '45', 'directors': ['涅提·蒂瓦里'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2457983084.jpg', 'cover_x': 4500, 'id': '26387939'}, {'casts': ['泰伊·谢里丹', '奥利维亚·库克', '本·门德尔森', '马克·里朗斯', '丽娜·维特'], 'cover_y': 3000, 'rate': '8.7', 'url': 'https://movie.douban.com/subject/4920389/', 'title': '头号玩家', 'star': '45', 'directors': ['史蒂文·斯皮尔伯格'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2516578307.jpg', 'cover_x': 2000, 'id': '4920389'}, {'casts': ['周杰伦', '庾澄庆', '谢霆锋', '李健'], 'cover_y': 1076, 'rate': '6.2', 'url': 'https://movie.douban.com/subject/27187829/', 'title': '中国好声音 第五季', 'star': '30', 'directors': ['金磊'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2527870040.jpg', 'cover_x': 690, 'id': '27187829'}, {'casts': ['米拉·库尼斯', '凯特·麦克金农', '贾斯汀·塞洛克斯', '萨姆·修汉', '薇尔玛·斯泽克斯'], 'cover_y': 1600, 'rate': '6.5', 'url': 'https://movie.douban.com/subject/26999424/', 'title': '我的间谍前男友', 'star': '35', 'directors': ['苏珊娜·福格尔'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2533822396.jpg', 'cover_x': 1038, 'id': '26999424'}, {'casts': ['张译', '黄景瑜', '海清', '杜江', '蒋璐霞'], 'cover_y': 2000, 'rate': '8.3', 'url': 'https://movie.douban.com/subject/26861685/', 'title': '红海行动', 'star': '40', 'directors': ['林超贤'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2514119443.jpg', 'cover_x': 1429, 'id': '26861685'}, {'casts': ['彭于晏', '廖凡', '姜文', '周韵', '许晴'], 'cover_y': 2867, 'rate': '7.2', 'url': 'https://movie.douban.com/subject/26366496/', 'title': '邪不压正', 'star': '35', 'directors': ['姜文'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2526297221.jpg', 'cover_x': 2048, 'id': '26366496'}, {'casts': ['蒂姆·罗宾斯', '摩根·弗里曼', '鲍勃·冈顿', '威廉姆·赛德勒', '克兰西·布朗'], 'cover_y': 2963, 'rate': '9.6', 'url': 'https://movie.douban.com/subject/1292052/', 'title': '肖申克的救赎', 'star': '50', 'directors': ['弗兰克·德拉邦特'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p480747492.jpg', 'cover_x': 2000, 'id': '1292052'}, {'casts': ['杰森·斯坦森', '李冰冰', '雷恩·威尔森', '鲁比·罗丝', '赵文瑄'], 'cover_y': 1399, 'rate': '5.9', 'url': 'https://movie.douban.com/subject/26426194/', 'title': '巨齿鲨', 'star': '30', 'directors': ['乔·德特杜巴'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2530572643.jpg', 'cover_x': 1000, 'id': '26426194'}, {'casts': ['神木隆之介', '上白石萌音', '长泽雅美', '市原悦子', '成田凌'], 'cover_y': 2000, 'rate': '8.4', 'url': 'https://movie.douban.com/subject/26683290/', 'title': '你的名字。', 'star': '40', 'directors': ['新海诚'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2395733377.jpg', 'cover_x': 1428, 'id': '26683290'}, {'casts': ['阿米尔·汗', '卡琳娜·卡普尔', '马达范', '沙尔曼·乔希', '奥米·瓦依达'], 'cover_y': 4364, 'rate': '9.2', 'url': 'https://movie.douban.com/subject/3793023/', 'title': '三傻大闹宝莱坞', 'star': '45', 'directors': ['拉吉库马尔·希拉尼'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p579729551.jpg', 'cover_x': 3030, 'id': '3793023'}, {'casts': ['吴京', '弗兰克·格里罗', '吴刚', '张翰', '卢靖姗'], 'cover_y': 1548, 'rate': '7.1', 'url': 'https://movie.douban.com/subject/26363254/', 'title': '战狼2', 'star': '35', 'directors': ['吴京'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2494701965.jpg', 'cover_x': 1024, 'id': '26363254'}, {'casts': ['姜文', '葛优', '周润发', '刘嘉玲', '陈坤'], 'cover_y': 2200, 'rate': '8.7', 'url': 'https://movie.douban.com/subject/3742360/', 'title': '让子弹飞', 'star': '45', 'directors': ['姜文'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p1512562287.jpg', 'cover_x': 1500, 'id': '3742360'}, {'casts': ['苏拉·沙玛', '伊尔凡·可汗', '拉菲·斯波', '阿迪勒·侯赛因', '塔布'], 'cover_y': 5000, 'rate': '9.0', 'url': 'https://movie.douban.com/subject/1929463/', 'title': '少年派的奇幻漂流', 'star': '45', 'directors': ['李安'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p1784592701.jpg', 'cover_x': 3375, 'id': '1929463'}, {'casts': ['平采娜·乐维瑟派布恩', '马里奥·毛瑞尔', '苏达拉·布查蓬', '雅尼卡·桑普蕾舞', '诺特·阿查拉那·阿瑞亚卫考'], 'cover_y': 1829, 'rate': '8.3', 'url': 'https://movie.douban.com/subject/4739952/', 'title': '初恋这件小事', 'star': '40', 'directors': ['普特鹏·普罗萨卡·那·萨克那卡林', '华森·波克彭'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p1505312273.jpg', 'cover_x': 1280, 'id': '4739952'}, {'casts': ['萨姆·沃辛顿', '佐伊·索尔达娜', '西格妮·韦弗', '史蒂芬·朗', '米歇尔·罗德里格兹'], 'cover_y': 1185, 'rate': '8.6', 'url': 'https://movie.douban.com/subject/1652587/', 'title': '阿凡达', 'star': '45', 'directors': ['詹姆斯·卡梅隆'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p492458287.jpg', 'cover_x': 800, 'id': '1652587'}, {'casts': ['金·凯瑞', '劳拉·琳妮', '艾德·哈里斯', '诺亚·艾默里奇', '娜塔莎·麦克艾霍恩'], 'cover_y': 1500, 'rate': '9.2', 'url': 'https://movie.douban.com/subject/1292064/', 'title': '楚门的世界', 'star': '45', 'directors': ['彼得·威尔'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p479682972.jpg', 'cover_x': 997, 'id': '1292064'}, {'casts': ['让·雷诺', '娜塔莉·波特曼', '加里·奥德曼', '丹尼·爱罗', '彼得·阿佩尔'], 'cover_y': 980, 'rate': '9.4', 'url': 'https://movie.douban.com/subject/1295644/', 'title': '这个杀手不太冷', 'star': '45', 'directors': ['吕克·贝松'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p511118051.jpg', 'cover_x': 658, 'id': '1295644'}, {'casts': ['陈坤', '倪妮', '赵立新', '倪大红', '袁弘'], 'cover_y': 2976, 'rate': '8.2', 'url': 'https://movie.douban.com/subject/26761328/', 'title': '天盛长歌', 'star': '40', 'directors': ['沈严', '刘海波'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2530496815.jpg', 'cover_x': 2126, 'id': '26761328'}, {'casts': ['马修·麦康纳', '安妮·海瑟薇', '杰西卡·查斯坦', '卡西·阿弗莱克', '迈克尔·凯恩'], 'cover_y': 7200, 'rate': '9.2', 'url': 'https://movie.douban.com/subject/1889243/', 'title': '星际穿越', 'star': '45', 'directors': ['克里斯托弗·诺兰'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2206088801.jpg', 'cover_x': 4858, 'id': '1889243'}, {'casts': ['刘德华', '梁朝伟', '黄秋生', '曾志伟', '郑秀文'], 'cover_y': 879, 'rate': '9.1', 'url': 'https://movie.douban.com/subject/1307914/', 'title': '无间道', 'star': '45', 'directors': ['刘伟强', '麦兆辉'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2233971046.jpg', 'cover_x': 580, 'id': '1307914'}]}
------------------------------------------------------------
{'data': [{'casts': ['沈腾', '马丽', '尹正', '艾伦', '王智'], 'cover_y': 8268, 'rate': '7.5', 'url': 'https://movie.douban.com/subject/25964071/', 'title': '夏洛特烦恼', 'star': '40', 'directors': ['闫非', '彭大魔'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2264377763.jpg', 'cover_x': 5906, 'id': '25964071'}, {'casts': ['周冬雨', '马思纯', '李程彬', '李萍', '蔡纲'], 'cover_y': 900, 'rate': '7.6', 'url': 'https://movie.douban.com/subject/25827935/', 'title': '七月与安生', 'star': '40', 'directors': ['曾国祥'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2378140502.jpg', 'cover_x': 644, 'id': '25827935'}, {'casts': ['本·贝尔特', '艾丽莎·奈特', '杰夫·格尔林', '佛莱德·威拉特', '西格妮·韦弗'], 'cover_y': 4447, 'rate': '9.3', 'url': 'https://movie.douban.com/subject/2131459/', 'title': '机器人总动员', 'star': '45', 'directors': ['安德鲁·斯坦顿'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p1461851991.jpg', 'cover_x': 3000, 'id': '2131459'}, {'casts': ['拉妮·玛克赫吉', '内拉吉·卡比', '萨钦', '苏普丽雅·皮尔加卡尔', '罗特·萨拉夫'], 'cover_y': 6824, 'rate': '7.5', 'url': 'https://movie.douban.com/subject/30140571/', 'title': '嗝嗝老师', 'star': '40', 'directors': ['西达夫·马贺拉'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2535365481.jpg', 'cover_x': 4872, 'id': '30140571'}, {'casts': ['周星驰', '吴孟达', '朱茵', '蔡少芬', '蓝洁瑛'], 'cover_y': 5103, 'rate': '9.2', 'url': 'https://movie.douban.com/subject/1292213/', 'title': '大话西游之大圣娶亲', 'star': '45', 'directors': ['刘镇伟'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2455050536.jpg', 'cover_x': 3645, 'id': '1292213'}, {'casts': ['文章', '包贝尔', '郭京飞', '李成敏', '辣目洋子'], 'cover_y': 2100, 'rate': '3.7', 'url': 'https://movie.douban.com/subject/27149818/', 'title': '胖子行动队', 'star': '20', 'directors': ['包贝尔'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2526215398.jpg', 'cover_x': 1500, 'id': '27149818'}, {'casts': ['爱德华·阿斯纳', '克里斯托弗·普卢默', '乔丹·长井', '鲍勃·彼德森', '戴尔里·林多'], 'cover_y': 3000, 'rate': '8.9', 'url': 'https://movie.douban.com/subject/2129039/', 'title': '飞屋环游记', 'star': '45', 'directors': ['彼特·道格特', '鲍勃·彼德森'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2364094053.jpg', 'cover_x': 2025, 'id': '2129039'}, {'casts': ['热拉尔·朱尼奥', '让-巴蒂斯特·莫尼耶', '弗朗索瓦·贝莱昂', '凯德·麦拉德', '玛丽·布奈尔'], 'cover_y': 655, 'rate': '9.2', 'url': 'https://movie.douban.com/subject/1291549/', 'title': '放牛班的春天', 'star': '45', 'directors': ['克里斯托夫·巴拉蒂'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p1910824951.jpg', 'cover_x': 491, 'id': '1291549'}, {'casts': ['科林·伍德尔', '斯蒂芬妮·诺格拉斯', '瑞贝卡·瑞滕豪斯', '安德鲁斯·李斯', '贝蒂·加布里埃尔'], 'cover_y': 1000, 'rate': '7.9', 'url': 'https://movie.douban.com/subject/26725678/', 'title': '解除好友2:暗网', 'star': '40', 'directors': ['斯蒂芬·思科'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2525020357.jpg', 'cover_x': 694, 'id': '26725678'}, {'casts': ['安德鲁·加菲尔德', '萨姆·沃辛顿', '文斯·沃恩', '雨果·维文', '卢克·布雷西'], 'cover_y': 2076, 'rate': '8.7', 'url': 'https://movie.douban.com/subject/26325320/', 'title': '血战钢锯岭', 'star': '45', 'directors': ['梅尔·吉布森'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2398141939.jpg', 'cover_x': 1417, 'id': '26325320'}, {'casts': ['奥黛丽·赫本', '格利高里·派克', '埃迪·艾伯特', '哈特利·鲍尔', '哈考特·威廉姆斯'], 'cover_y': 2400, 'rate': '9.0', 'url': 'https://movie.douban.com/subject/1293839/', 'title': '罗马假日', 'star': '45', 'directors': ['威廉·惠勒'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2189265085.jpg', 'cover_x': 1600, 'id': '1293839'}, {'casts': ['莱昂纳多·迪卡普里奥', '凯特·温丝莱特', '比利·赞恩', '凯西·贝茨', '弗兰西丝·费舍'], 'cover_y': 3000, 'rate': '9.3', 'url': 'https://movie.douban.com/subject/1292722/', 'title': '泰坦尼克号', 'star': '45', 'directors': ['詹姆斯·卡梅隆'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p457760035.jpg', 'cover_x': 2015, 'id': '1292722'}, {'casts': ['塞伊拉·沃西', '梅·维贾', '阿米尔·汗', '拉杰·阿晶', '提斯·沙马'], 'cover_y': 800, 'rate': '7.7', 'url': 'https://movie.douban.com/subject/26942674/', 'title': '神秘巨星', 'star': '40', 'directors': ['阿德瓦·香登'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2508925590.jpg', 'cover_x': 568, 'id': '26942674'}, {'casts': ['柯震东', '陈妍希', '敖犬', '郝劭文', '蔡昌宪'], 'cover_y': 720, 'rate': '8.1', 'url': 'https://movie.douban.com/subject/4920528/', 'title': '那些年,我们一起追的女孩', 'star': '40', 'directors': ['九把刀'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p1062824805.jpg', 'cover_x': 512, 'id': '4920528'}, {'casts': ['奥黛丽·塔图', '马修·卡索维茨', '吕菲斯', '洛莱拉·克拉沃塔', '塞尔日·梅兰'], 'cover_y': 1900, 'rate': '8.7', 'url': 'https://movie.douban.com/subject/1292215/', 'title': '天使爱美丽', 'star': '45', 'directors': ['让-皮埃尔·热内'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p803896904.jpg', 'cover_x': 1278, 'id': '1292215'}, {'casts': ['冯绍峰', '陈柏霖', '钟汉良', '王珞丹', '袁泉'], 'cover_y': 9213, 'rate': '7.1', 'url': 'https://movie.douban.com/subject/25805741/', 'title': '后会无期', 'star': '35', 'directors': ['韩寒'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2195469915.jpg', 'cover_x': 6458, 'id': '25805741'}, {'casts': ['安东尼·冈萨雷斯', '盖尔·加西亚·贝纳尔', '本杰明·布拉特', '阿兰纳·乌巴奇', '芮妮·维克托'], 'cover_y': 2048, 'rate': '9.0', 'url': 'https://movie.douban.com/subject/20495023/', 'title': '寻梦环游记', 'star': '45', 'directors': ['李·昂克里奇', '阿德里安·莫利纳'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2503997609.jpg', 'cover_x': 1432, 'id': '20495023'}, {'casts': ['张国荣', '王祖贤', '午马', '刘兆铭', '林威'], 'cover_y': 2100, 'rate': '8.6', 'url': 'https://movie.douban.com/subject/1297447/', 'title': '倩女幽魂', 'star': '45', 'directors': ['程小东'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2414157745.jpg', 'cover_x': 1400, 'id': '1297447'}, {'casts': ['岳丽娜', '于毅', '张少华', '史可', '刘智扬'], 'cover_y': 4523, 'rate': '2.7', 'url': 'https://movie.douban.com/subject/26877848/', 'title': '娘道', 'star': '15', 'directors': ['郭靖宇', '巨兴茂'], 'cover': 'https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2522104204.jpg', 'cover_x': 2900, 'id': '26877848'}, {'casts': ['金妮弗·古德温', '杰森·贝特曼', '伊德里斯·艾尔巴', '珍妮·斯蕾特', '内特·托伦斯'], 'cover_y': 2005, 'rate': '9.1', 'url': 'https://movie.douban.com/subject/25662329/', 'title': '疯狂动物城', 'star': '45', 'directors': ['拜伦·霍华德', '瑞奇·摩尔', '杰拉德·布什'], 'cover': 'https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2315672647.jpg', 'cover_x': 1418, 'id': '25662329'}]}
------------------------------------------------------------

总结一下

我们回顾一下刚才我们做了什么,目前很多网站采用了 ajax 异步加载网页的方法,这种方法的好处就是可以在不重新加载整个页面的情况下,与服务器交换数据并更新部分网页内容。这也就意味着我们无法仅通过 url 获取到网页中的全部内容(因为不论后续加载了多少内容,网页的url始终没有变过)。

所以我们使用抓包工具查看了一下页面,看看“加载更多”是后台发生了什么事儿,然后我们发现,每次加载时都会出现一个新的响应,这些响应的 url 具有相似的结构,并且在浏览器中直接访问这些 url 时,出现了刚才新刷新出来的内容的 json 格式数据。所以我们明白了,ajax 异步加载网页就是通过这些请求来不断与服务器交换数据的。

接下来的事情就简单了,我们通过爬虫去访问这些响应的 url(可以通过改变参数来控制访问的数量),这样数据不就手到擒来了吗?

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:设计师小姐姐 返回首页