我在这里拥有的脚本从解析的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)