软件工程2班林仁满

import requests
from bs4 import BeautifulSoup as btfs

headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0'}
url='https://movie.douban.com/top250'
r = requests.get(url,timeout=30,headers=headers)
soup = btfs(r.text,'html.parser')

tag = soup.find_all('div',class_='hd')
name=[]
for i in tag:
    name.append(i.a.span.text)#电影名

fen= soup.find_all('span',class_="rating_num")
pingfen=[]
for u in fen:
    pingfen.append(u.text)#评分
    
pj=soup.find_all('span',class_="inq")
pingjia=[]
for o in pj:
    pingjia.append(o.text)#评价

    
for p in range(25):
    print('第{}名 {},评分{},评价:{}'.format(p+1,name[p],pingfen[p],pingjia[p]))

你可能感兴趣的:(软件工程2班林仁满)