imdb电影爬取代码 import requests from bs4 import BeautifulSoup import pandas as pd import time import numpy as np import random def bs_dealing(bs): movies_lst = [] global page for movie in bs.findAll('div', {'class': 'lister-item-content'}): title = movie.find('a').string year = movie.find('span', { 'class': 'lister-item-year text-muted unbold' }).string genres = movie.find('span', 'genre').string genres = genres.strip('\n').strip() # 控制网页返回的错误,runtime是否为空,以免数据无法正常写入 if movie.find('span', 'runtime') is not None: runtime = movie.find('span', 'runtime').string else: runtime = 0 rating = movie.find('div', { 'class': "inline-block ratings-imdb-ra