(二)python爬取猫眼电影TOP100榜并将电影信息写入到Excel(Excel列宽自适应)
# -*- coding:utf-8 -*- import requests from bs4 import BeautifulSoup import xlrd,xlwt urls = [ "https://maoyan.com/board/4?offset={}".format(i) for i in range(0,100,10) ] header = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (" "KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" } length = {} def len_byte(value): length = len(value) utf8_length = len(value.encode('utf-8')) length = (utf8_length - length)/2 + length return int(length) #电影 主演 时间 国家 评分 def FilmInformation(url): content = [] r = requests.get(url,headers = header) respond = r.text soup =