import requests,os,json
from lxml import etree
from pymysql import *
class Movie(object):
def __init__(self):
self.url="https://www.360kan.com/dianying/list.php?year=all&area=all&act=all&cat=106&pageno={}"
self.headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36'}
self.start=0
# 请求数据接受数据
def get_data(self,url):
response = requests.get(url,headers=self.headers)
return response.content
# 解析数据
def xml_data(self,data):
html = etree.HTML(data)
mes = html.xpath("//ul[@class='list g-clear']/*")
dict = {}
for i in mes:
dict['title'] = i.xpath("./a[@class='js-tongjic']/div[@class='detail']/p/span/text()")[0]
dict['zhuyan'] = i.xpath("./a[@class='js-tongjic']/div[@class='detail']/p[last()]/text()")[0]
info_url = "https://www.360kan.com" + i.xpath("./a[@class='js-tongjic']/@href")[0] poto_url = i.xpath("./a[@class='js-tongjic']/div[@class='cover g-playicon']/img/@src")
potoname =self.write_poto(poto_url)
dict['poto'] = potoname
mes = self.get_data(info_url)
meslist = etree.HTML(mes)
mes_info = meslist.xpath("//div[@class='top-info-detail g-clear']")
dictid = self.write_database(dict)
for w in mes_info:
dict1 = {}
dict1['daoyan'] = w.xpath("./div[@class='g-clear item-wrap']/p[5]/a/text()")[0]
dict1['diqu'] = w.xpath("./div[@class='g-clear item-wrap']/p[3]/text()")[0]
dict1['year'] = w.xpath("./div[@class='g-clear item-wrap']/p[2]/text()")[0]
dict1['info'] = w.xpath("./div[@class='item-desc-wrap g-clear js-open-wrap']/p/text()")[0]
dict1['t_id'] = str(dictid)
self.info_write_database(dict1)
# 存图片
def write_poto(self,data):
path = "d:/img/"
if not os.path.exists(path):
os.makedirs(path)
for n in data:
poto_mes = self.get_data(n)
potoname = n.split("/")[-1]
with open(path+potoname,"wb") as f:
f.write(poto_mes)
return potoname
# 写入数据库
def database(self):
conn = connect(host="127.0.0.1",port=3306,user="root",password="mysql",database="lianxi",charset="utf8mb4")
cur = conn.cursor()
return cur,conn
# 写入数据库
def write_database(self,data):
cur,conn = self.database()
title = data["title"]
zhuyan = data["zhuyan"]
poto = data["poto"]
try:
cur.execute("insert into movie values(0,'"+title+"','"+zhuyan+"','"+poto+"')")
except:
pass
new_id = cur.lastrowid
conn.commit() return new_id # 读取数据库
def read_database(self,):
cur,conn = self.database()
cur.execute("select * from movie inner join movies on movie.id=movies.t_id limit 10;")
ret =cur.fetchall()
cur.close()
conn.close()
list = json.dumps(ret,ensure_ascii=False)
print(list)
# info写入数据库
def info_write_database(self,data1):
cur,conn = self.database()
cur.execute("insert into movies values(0,'"+data1['daoyan']+"','"+data1['diqu']+"','"+data1['year']+"','"+data1['info']+"','"+data1['t_id']+"')")
conn.commit() def run(self):
while True:
url = self.url.format(self.start)
data = self.get_data(url)
if data ==[]:
break
else:
if self.start == 2:
break
else:
self.start+=1
self.xml_data(data) if __name__ == '__main__':
movie = Movie()
movie.run()
movie.read_database()

360电影主页和详情页爬去入Mysql库链表读取--lowbiprogrammer的更多相关文章

  1. bokeyuan_python文章爬去入mongodb读取--LOWBIPROGRAMMER

    # -*- coding: utf-8 -*- import requests,os from lxml import etree from pymongo import * class Boke(o ...

  2. java批量爬去电影资源

    摘要 网上有很多个人站来分享电影资源,其实有时候我们自己也想做这个一个电影站来分享资源.但是这个时候就有一个问题,电影的资源应该从哪里来呢?难道要自己一条条手动去从网络上获取,这样无疑是缓慢而又效率低 ...

  3. Android 自定义控件 轻松实现360软件详情页

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/43649913,本文出自:[张鸿洋的博客] 1.概述 最近有不少朋友私聊问应用宝. ...

  4. 多线程爬虫爬取详情页HTML

    注意:如果想爬取详情页的信息请按须添加方法 import requests import os import re import threading from lxml import etree #爬 ...

  5. 1、找出url汇总页,过滤出满足条件的详情页url;2、去详情页采集信息

    1.找出url汇总页,过滤出满足条件的详情页url:2.去详情页采集信息 package main import ( "fmt" "github.com/gocolly/ ...

  6. 潭州课堂25班:Ph201805201 django 项目 第二十三课 文章主页 轮播图前端实现 热门新闻推荐实现 详情页实现 (课堂笔记)

    前台代码 // 在static/js/news/index.js文件中 $(function () { // 新闻列表功能 let $newsLi = $(".news-nav ul li& ...

  7. scrapy爬取网址,进而爬取详情页问题

    1.最容易出现的问题是爬取到的url大多为相对路径,如果直接将爬取到的url进行二次爬取就会出现以下报错: raise ValueError('Missing scheme in request ur ...

  8. 【京东详情页】——原生js爬坑之放大镜

    一.引言 在商城的详情页中,放大镜的功能是很常见的.这里京东详情页就要做一个仿放大镜的效果,预览如下: 二.实现原理 实际上,放大镜的实现是单纯用几个div,鼠标移入其中一个小图div,触发事件显示另 ...

  9. 【京东详情页】——原生js爬坑之标签页

    一.引言 要做详情页的商品评价等5个li的标签页转换,效果如下: 二.实现原理 有一个特别的地方:上面五个li,但下面只有四个容器(table/div). 设计的目的:无论点哪个li,只有前四个div ...

随机推荐

  1. 使用 redis “捕捉” “用户登录过期” 事件

    实现原理及步骤: 1)登录时,计算登录过期时间,以分钟为单位作key(例如:sign_timeout_201705212233),value方面自己发挥,需要什么数据就拼什么数据进去,只是要注意,一定 ...

  2. vux ajax请求 及 跨域

    1)使用 AjaxPlugin 插件(在组件里使用) 引入插件 import { AjaxPlugin } from 'vux' 初始化 export default { components: { ...

  3. 【代码审计】EasySNS_V1.6远程图片本地化导致Getshell

    0x00 环境准备 EasySNS官网:http://www.imzaker.com 网站源码版本:EasySNS极简社区V1.60 程序源码下载:http://es.imzaker.com/inde ...

  4. Java读取maven目录下的*.properties配置文件

    public class ReadProperties{ private static String proFileName = "/config/MQSubjectId.propertie ...

  5. Malab 常用数学函数

    l        三角函数和双曲函数 名称 含义 名称 含义 名称 含义 sin 正弦 csc 余割 atanh 反双曲正切 cos 余弦 asec 反正割 acoth 反双曲余切 tan 正切 ac ...

  6. C语言字节对齐问题详解

    引言 考虑下面的结构体定义: typedef struct{ char c1; short s; char c2; int i; }T_FOO; 假设这个结构体的成员在内存中是紧凑排列的,且c1的起始 ...

  7. Git学习之msysGit环境支持

    ============================== msysGit中Shell环境的中文支持 ============================== 1 中文录入的问题 默认的Shel ...

  8. Disk Genius 彻底清理硬盘空闲

  9. Shell 中的反引号(`),单引号('),双引号(")

    在写shell的时候老是傻傻分不清楚,今天来理一理. 1.反引号位 (`) 位于键盘的Tab键的上方.1键的左方.注意与单引号(')位于Enter键的左方的区别. 在Linux中起着命令替换的作用.命 ...

  10. css3整理--rgba

    rgba语法: rgba(0, 0, 0,0.5); 第一个参数:R 红色(0-255) 第二个参数:G 绿色(0-255) 第三个参数:B 蓝色(0-255) 第四个参数:透明度(0-1)使用rgb ...