数据获取方式:微信搜索关注【靠谱杨阅读人生】回复【电影】。
整理不易,资源付费,谢谢支持!

代码:

  1 import time
2 import traceback
3 import requests
4 from lxml import etree
5 import re
6 from bs4 import BeautifulSoup
7 from lxml.html.diff import end_tag
8 import json
9 import pymysql
10
11 def get1905():
12 url='https://www.1905.com/vod/list/n_1/o3p1.html'
13 headers={
14 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
15 }
16 templist=[]
17 dataRes=[]
18 #最热
19 #1905电影网一共有99页,每页24部电影 for1-100 输出1-99页
20 for i in range(1,100):
21 url_1='https://www.1905.com/vod/list/n_1/o3p'
22 auto=str(i)
23 url_2='.html'
24 url=url_1+auto+url_2
25 print(url)
26 response = requests.get(url, headers)
27 response.encoding = 'utf-8'
28 page_text = response.text
29 soup = BeautifulSoup(page_text, 'lxml')
30 # print(page_text)
31 movie_all = soup.find_all('div', class_="grid-2x grid-3x-md grid-6x-sm")
32 for single in movie_all:
33 part_html=str(single)
34 part_soup=BeautifulSoup(part_html,'lxml')
35 #添加名字
36 name=part_soup.find('a')['title']
37 templist.append(name)
38 # print(name)
39 #添加评分
40 try:
41 score=part_soup.find('i').text
42 except:
43 if(len(score)==0):
44 score="1905暂无评分"
45 templist.append(score)
46 # print(score)
47 #添加path
48 path=part_soup.find('a',class_="pic-pack-outer")['href']
49 templist.append(path)
50 # print(path)
51 #添加state
52 state="免费"
53 templist.append(state)
54 print(templist)
55 dataRes.append(templist)
56 templist=[]
57 print(len(dataRes))
58 # print(movie_all)
59
60 #---------------------------------------------
61 #好评
62 templist = []
63 # 1905电影网一共有99页,每页24部电影 for1-100 输出1-99页
64 for i in range(1, 100):
65 url_1 = 'https://www.1905.com/vod/list/n_1/o4p'
66 auto = str(i)
67 url_2 = '.html'
68 url = url_1 + auto + url_2
69 print(url)
70 response = requests.get(url, headers)
71 response.encoding = 'utf-8'
72 page_text = response.text
73 soup = BeautifulSoup(page_text, 'lxml')
74 # print(page_text)
75 movie_all = soup.find_all('div', class_="grid-2x grid-3x-md grid-6x-sm")
76 for single in movie_all:
77 part_html = str(single)
78 part_soup = BeautifulSoup(part_html, 'lxml')
79 # 添加名字
80 name = part_soup.find('a')['title']
81 templist.append(name)
82 # print(name)
83 # 添加评分
84 try:
85 score = part_soup.find('i').text
86 except:
87 if (len(score) == 0):
88 score = "1905暂无评分"
89 templist.append(score)
90 # print(score)
91 # 添加path
92 path = part_soup.find('a', class_="pic-pack-outer")['href']
93 templist.append(path)
94 # print(path)
95 # 添加state
96 state = "免费"
97 templist.append(state)
98 print(templist)
99 dataRes.append(templist)
100 templist = []
101 print(len(dataRes))
102 #---------------------------------------------
103 # 最新
104 templist = []
105 # 1905电影网一共有99页,每页24部电影 for1-100 输出1-99页
106 for i in range(1, 100):
107 url_1 = 'https://www.1905.com/vod/list/n_1/o1p'
108 auto = str(i)
109 url_2 = '.html'
110 url = url_1 + auto + url_2
111 print(url)
112 response = requests.get(url, headers)
113 response.encoding = 'utf-8'
114 page_text = response.text
115 soup = BeautifulSoup(page_text, 'lxml')
116 # print(page_text)
117 movie_all = soup.find_all('div', class_="grid-2x grid-3x-md grid-6x-sm")
118 for single in movie_all:
119 part_html = str(single)
120 part_soup = BeautifulSoup(part_html, 'lxml')
121 # 添加名字
122 name = part_soup.find('a')['title']
123 templist.append(name)
124 # print(name)
125 # 添加评分
126 try:
127 score = part_soup.find('i').text
128 except:
129 if (len(score) == 0):
130 score = "1905暂无评分"
131 templist.append(score)
132 # print(score)
133 # 添加path
134 path = part_soup.find('a', class_="pic-pack-outer")['href']
135 templist.append(path)
136 # print(path)
137 # 添加state
138 state = "免费"
139 templist.append(state)
140 print(templist)
141 dataRes.append(templist)
142 templist = []
143 print(len(dataRes))
144 #去重
145 old_list = dataRes
146 new_list = []
147 for i in old_list:
148 if i not in new_list:
149 new_list.append(i)
150 print(len(new_list))
151 print("总数: "+str(len(new_list)))
152 return new_list
153 def insert_1905():
154 cursor = None
155 conn = None
156 try:
157 count = 0
158 list = get1905()
159 print(f"{time.asctime()}开始插入1905电影数据")
160 conn, cursor = get_conn()
161 sql = "insert into movie1905 (id,name,score,path,state) values(%s,%s,%s,%s,%s)"
162 for item in list:
163 print(item)
164 # 异常捕获,防止数据库主键冲突
165 try:
166 cursor.execute(sql, [0, item[0], item[1], item[2], item[3]])
167 except pymysql.err.IntegrityError:
168 print("重复!跳过!")
169 conn.commit() # 提交事务 update delete insert操作
170 print(f"{time.asctime()}插入1905电影数据完毕")
171 except:
172 traceback.print_exc()
173 finally:
174 close_conn(conn, cursor)
175 return;
176
177 #连接数据库 获取游标
178 def get_conn():
179 """
180 :return: 连接,游标
181 """
182 # 创建连接
183 conn = pymysql.connect(host="127.0.0.1",
184 user="root",
185 password="000429",
186 db="movierankings",
187 charset="utf8")
188 # 创建游标
189 cursor = conn.cursor() # 执行完毕返回的结果集默认以元组显示
190 if ((conn != None) & (cursor != None)):
191 print("数据库连接成功!游标创建成功!")
192 else:
193 print("数据库连接失败!")
194 return conn, cursor
195 #关闭数据库连接和游标
196 def close_conn(conn, cursor):
197 if cursor:
198 cursor.close()
199 if conn:
200 conn.close()
201 return 1
202
203 if __name__ == '__main__':
204 # get1905()
205 insert_1905()

运行截图:

数据库

Python爬虫爬取1905电影网视频电影并存储到mysql数据库的更多相关文章

  1. Python爬虫爬取BT之家找电影资源

    一.写在前面 最近看新闻说圣城家园(SCG)倒了,之前BT天堂倒了,暴风影音也不行了,可以说看个电影越来越费力,国内大厂如企鹅和爱奇艺最近也出现一些幺蛾子,虽然目前版权意识虽然越来越强,但是很多资源在 ...

  2. 如何利用python爬虫爬取爱奇艺VIP电影?

    环境:windows    python3.7 思路: 1.先选取你要爬取的电影 2.用vip解析工具解析,获取地址 3.写好脚本,下载片断 4.将片断利用电脑合成 需要的python模块: ##第一 ...

  3. Python爬虫---爬取抖音短视频

    目录 前言 抖音爬虫制作 选定网页 分析网页 提取id构造网址 拼接数据包链接 获取视频地址 下载视频 全部代码 实现结果 待解决的问题 前言 最近一直想要写一个抖音爬虫来批量下载抖音的短视频,但是经 ...

  4. python爬虫–爬取煎蛋网妹子图片

    前几天刚学了python网络编程,书里没什么实践项目,只好到网上找点东西做. 一直对爬虫很好奇,所以不妨从爬虫先入手吧. Python版本:3.6 这是我看的教程:Python - Jack -Cui ...

  5. Python 爬虫 爬取 煎蛋网 图片

    今天, 试着爬取了煎蛋网的图片. 用到的包: urllib.request os 分别使用几个函数,来控制下载的图片的页数,获取图片的网页,获取网页页数以及保存图片到本地.过程简单清晰明了 直接上源代 ...

  6. python爬虫爬取煎蛋网妹子图片

    import urllib.request import os def url_open(url): req = urllib.request.Request(url) req.add_header( ...

  7. Python爬虫训练:爬取酷燃网视频数据

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理 项目目标 爬取酷燃网视频数据 https://krcom.cn/ 环境 Py ...

  8. 利用Python网络爬虫爬取学校官网十条标题

    利用Python网络爬虫爬取学校官网十条标题 案例代码: # __author : "J" # date : 2018-03-06 # 导入需要用到的库文件 import urll ...

  9. 用Python爬虫爬取广州大学教务系统的成绩(内网访问)

    用Python爬虫爬取广州大学教务系统的成绩(内网访问) 在进行爬取前,首先要了解: 1.什么是CSS选择器? 每一条css样式定义由两部分组成,形式如下: [code] 选择器{样式} [/code ...

  10. Python爬虫爬取全书网小说,程序源码+程序详细分析

    Python爬虫爬取全书网小说教程 第一步:打开谷歌浏览器,搜索全书网,然后再点击你想下载的小说,进入图一页面后点击F12选择Network,如果没有内容按F5刷新一下 点击Network之后出现如下 ...

随机推荐

  1. html中iframe调用兄弟iframe中的js方法

    问题说明 最近工作中碰到一个页面有一个主iframe A,用于操作主要业务元素.其中有一个弹出框里面也嵌入了一个iframe B, 此时,我需要在B中调用A中JS的指定方法.下面咱们来通过例子还原一下 ...

  2. git tag 常用操作-创建、查看、推送、删除等

    创建tag 1.创建tag: git tag -a v0.0.1 或者 对某一提交的信息打tag标签,末尾是一个commit id git tag -a v0.0.1 cc16905 2.创建tag带 ...

  3. 【libGDX】使用Mesh绘制立方体

    1 前言 ​ 本文主要介绍使用 Mesh 绘制立方体,读者如果对 Mesh 不太熟悉,请回顾以下内容: 使用Mesh绘制三角形 使用Mesh绘制矩形 使用Mesh绘制圆形 ​ 在绘制立方体的过程中,主 ...

  4. gitee配置SSH公钥

    第一步,找个地方打开"git bash",然后输入生成ssh公钥的命令: ssh-keygen -t rsa -C 'your-email' 然后敲四次回车生成公钥: 第二步,输入 ...

  5. 【C# .Net】继承重写父类方法,C# 与 JAVA的不同之处

    一直都没仔细研究c#重写,new关键字的作用,最近在回头看书,复习C#基础的时候才发现了 C# 重写和 JAVA大不一样的地方. C# 提供特定实现的子类可以重写(override)标识为 virtu ...

  6. 第一百零四篇:DOM事件流

    好家伙,JS基础接着学,   1.事件流 页面哪个部分拥有特定的事件? 可以把页面想象成一个同心圆, 当你戳了其中的一点,其实你同时戳中了很多个圆   当你点击一个页面中的按钮,实际上你同时点击了这个 ...

  7. 【Azure 应用服务】访问App Service突然出现 ERR_SSL_PROTOCOL_ERROR错误的解答

    问题描述 在中国区的Azure  App Service服务中,新创建的站点突然访问出现 " This site can't provide a secure connection,xxxx ...

  8. 【Azure Developer】使用Azure Resource Graph的查询语法的示例

    文章"[Azure Developer]在Azure Resource Graph Explorer中查看当前订阅下的所有资源信息列表并导出(如VM的名称,IP地址内网/公网,OS,区域等) ...

  9. 【工具】用nvm管理nodejs版本切换,真香!

    前言 缘由 换个nodejs版本比换个媳妇还难,nvm堪称管理nodejs版本神器 事情的起因,公司的一些老项目需要依赖稳定老版本的nodejs,但是自己的一些项目所需要的是更高版本的nodejs,这 ...

  10. Java //100以内的质数的输出(从2开始,到这个数-1结束为止,都不能被这个数本身整除)+优化

    1 //100以内的质数的输出(从2开始,到这个数-1结束为止,都不能被这个数本身整除) 2 boolean isFlag = true; //标识i是否被j除尽,修改其值 3 4 for(int i ...