|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import requests
import re
import openpyxl
import sqlite3
file_name = re.compile(r'title="(.*?)"')
link_ = re.compile(r"<a href='(.*?).html'")
url = 'http://www.dytt89.com'
def main(url):
head = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36 Edg/103.0.1264.37"
}
response = requests.get(url,headers=head)#verify = False去除安全验证
response.encoding = 'gb2312'
tx = re.findall(file_name,response.text)
del tx[0]
return tx
def get_link(url):
#获取电影名对应链接
head = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36 Edg/103.0.1264.37"
}
response = requests.get(url,headers=head)#verify = False去除安全验证
response.encoding = 'gb2312'
tx = re.findall(file_name,response.text)
tx2 = re.findall(link_,response.text)
list1 = []
for each in tx2:
list1.append(url+each)
list1.reverse()
return list1
def save_pave(tx,list1):
connet = sqlite3.connect("电影名.db")
cur = connet.cursor()
sql = '''
create table if not exists 电影名称
(电影名 varchar(20),
电影链接 varchar(30)
);
'''
cur.execute(sql)
connet.commit()
for each1 in tx:
for each_one in list1:
sql ='''
insert into 电影名称(电影名,电影链接) values ('%s','%s')
'''%(each1,each_one)
cur.execute(sql)
continue
connet.commit()
cur.close()
connet.close()
sqlite3.IntegrityError: UNIQUE constraint failed: 电影名称.电影名 |
|