当先锋百科网

首页 1 2 3 4 5 6 7

import requests,sys,webbrowser,bs4,pprint,openpyxl
res=requests.get(‘https://movie.douban.com/chart’)
soup =bs4.BeautifulSoup(res.text,“html.parser”)
elemts=soup.select(’.nbg’)
moviename=[]
for i in range(len(elemts)):
moviename.append(elemts[i].get(‘title’))
movielink=[]
for i in range(len(elemts)):
movielink.append(elemts[i].get(‘href’))
movieresult=[]
for i in range(len(moviename)):
movieresult.append([i,moviename[i],movielink[i]])
wb=openpyxl.Workbook()
ws=wb.active
ws[‘a1’]=“电影名称”
ws[‘b1’]=“电影链接”
for each in movieresult:
ws.append(each)
wb.save(“豆瓣电影2.xlsx”)