import requests
import re
#爬取豆瓣电影排名
pageNum = int(input("要查看第几页电影分数:"))
#已知豆瓣默认每页展示20条
#url= "https://movie.douban.com/j/chart/top_list?type=11&interval_id=100%3A90&action=&start=0&limit=20"
url= "https://movie.douban.com/j/chart/top_list?type=11&interval_id=100%3A90&action=&start="+str((pageNum-1)*20)+"&limit=20"
#评分 "rating":["9.6","50"] 此处有中括号[],尽管加了r表示不转译,但是不加斜杠,仍然匹配不到。
pattern1 = r'"rating":["(.*?)","d+"]'
#电影名
pattern2 = r'"title":"(.*?)"'
#电影演员
pattern3 = r'"actors":[(.*?)]'
data = requests.get(url).text
print(data)
pat1 = re.compile(pattern1)
pat2 = re.compile(pattern2)
pat3 = re.compile(pattern3)
list1 = pat1.findall(data)
list2 = pat2.findall(data)
list3 = pat3.findall(data)
print(list1)
print(list2)
print(list3)
list = []
for i in range(0,len(list1)):
list.append(list2[i]+":"+list1[i]+"分,演员:"+list3[i])
print("---------------------------------------------")
for i in list:
print(i)