import time from urllib import request import re import random from fake_useragent import UserAgent import pymysql from hashlib import md5 class DianYing2345Spider(object): # 初始化以及连接数据库 def __init__(self): self.url='https://kan.2345.com/vip/list/--movie--0---{}.html' self.db=pymysql.connect(host='localhost',user='root',password='123456',database='filmskydb',charset='utf8') self.cursor=self.db.cursor() # 发起请求 def get_html(self,url): headers={ 'User-Agent': UserAgent().random } req=request.Request(url=url,headers=headers) res=request.urlopen(req) # 得到响应 html=res.read().decode('gb2312','ignore')#ignore忽略解析不了的字符串 return html # 解析一级页面得到个电影url def parse_html(self,one_url): #得到一级页面 one_html=self.get_html(one_url) #正则匹配 re_dbs='