import requests
from bs4 import BeautifulSoup
from openpyxl import Workbook
wb = Workbook()
sheet = wb.active
url = ‘https://movie.douban.com/top250’
ret = requests.get(url=url)
data = ret.text
soup = BeautifulSoup(data, ‘html.parser’)
ol = soup.find(name=‘ol’, attrs={‘class’: ‘grid_view’})
li_list = ol.find_all(name=‘li’)
sheet.titlt = ‘豆瓣好评电影’
sheet[‘A1’].value = ‘序号’
sheet[‘B1’].value = ‘电影名称’
sheet[‘C1’].value = ‘电影评分’
sheet[‘D1’].value = ‘电影链接’
sheet[‘E1’].value = ‘电影图片’
count = 1
for li in li_list:
name = li.find(name=‘span’, attrs={‘class’:‘title’})
rat = li.find(name=‘span’, attrs={‘class’: ‘rating_num’})
url = li.find(name=‘a’)
img = li.find(name=‘img’)
count += 1
sheet[‘A%s’ % count].value = count - 1
sheet[‘B%s’ % count].value = name.text
sheet[‘C%s’ % count].value = rat.text
sheet[‘D%s’ % count].value = url[‘href’]
sheet[‘E%s’ % count].value = img[‘src’]
wb.save(‘好评电影.xlsx’)
1683

被折叠的 条评论
为什么被折叠?



