不多说,直接上程序
#导库
import requests
import bs4z
import xlwt
import re
#伪装成浏览器访问
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'}
#创建Excel以备存储
Movie=xlwt.Workbook(encoding='utf-8')
sheet=Movie.add_sheet('豆瓣Top250电影', cell_overwrite_ok=True)
sheet.write(0, 0, '电影名')
sheet.write(0, 1, '导演')
sheet.write(0, 2, '主演')
sheet.write(0, 3, '年份')
sheet.write(0, 4, '国家')
sheet.write(0, 5, '类型')
sheet.write(0, 6, '简要')
#获取要爬取的页面
urls