api访问imdb最受好评的电影

时间:2019-10-06 02:43:35

标签: python

我在这里拥有的脚本从解析的HTML中找到电影的评级。如果我想说按流派找到前50名列表并以JSON格式(电影:等级)获取输出,该如何在python中获取此信息?使用API​​还是其他方法?

import requests
from bs4 import BeautifulSoup 

URL = "google.com/search?q={}"

def find_rating(name):
    ratings = {}
    r = requests.get(URL.format(name))
    s = BeautifulSoup(r.text, "html.parser")
    n = s.find_all("div", class_ = "sDYTm")
    for i in n:
        d = i.text.split(".")
        ratings[d[1]] = d[0]
    return ratings

if __name__ == "__main__":
    movie ="Good WIll Hunting"
    rating = find_rating(movie)
    print(rating)

0 个答案:

没有答案