#!/usr/bin/env python
# encoding: utf-8
import requests
from random import choice
from lxml import html
from urllib.parse import urljoin,quote
import os
import time
NAMEURLDIC={}
NAMEURLDIC_L2={}
ualist=["Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)",
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
"Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)",
"Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; http://help.yahoo.com/help/us/ysearch/slurp)"]
ua=choice(ualist)
header={"User_Agent":ua}
mailurl="https://press.mu"
url="https://press.mu/tag"
searc_url="https://press.mu/search/{}?p={}"
def getpage(url):
req=None
try:
req=requests.get(url=url,headers=header,stream=True)
req.encoding=req.apparent_encoding
except:
pass
return req
def parse(url):
source=getpage(url).text
if len(source):
root=html.fromstring(source)
return root
def buff(url):
buff = None
req=getpage(url)
return req
def save_file(title,url,type="m3u8"): if os.path.exists("pressimg"):
pass
else:
os.mkdir("pressimg")
with open(f'./pressimg/{title}.{type}',"wb") as fs:
fs.write(buff(url).content) root=parse(url)
taglist=root.xpath("//section[@id='tag']/ul/li/a")
for tag in taglist:
title=tag.xpath("./text()")[0]
href=urljoin(mailurl,tag.xpath("./@href")[0])
NAMEURLDIC.setdefault(title,href)
for k,v in NAMEURLDIC.items():
#第一页
root=parse(v)
#视频件数:
v_count=root.xpath("//p[@id='hit']/strong/text()")[0]
v_max_page_num=root.xpath("//nav[@id='pager']/ul/li[last()-1]/a/text()")[0]
print(f'当前分类为{k}:,视频件数为:{v_count}')
for item in range(1,int(v_max_page_num)+1):
print(f"获取第{item}页")
if item==1:
pass
else:
root = parse(searc_url.format(quote(title.strip()),item))
level2list=root.xpath("//section[@class='items']//h2/a")
for level2 in level2list:
title_level2 = level2.xpath("./text()")[0]
href_level2 = urljoin(mailurl, level2.xpath("./@href")[0])
NAMEURLDIC_L2.setdefault(title_level2, href_level2)
print(title_level2,href_level2)
root2 = parse(href_level2)
videourl=root2.xpath("//div[@id='player']//video/source/@src")[0]
imgurl="https:"+root2.xpath("//div[@id='player']//video/@poster")[0]
print("videourl",videourl)
print("imgurl",imgurl)
save_file(title_level2,videourl)
save_file(title_level2,imgurl,"jpg")
print("开始下载",f"{title_level2}.jpg")

  

pressmuSpiderr的更多相关文章

  1. Thymeleaf3.0内容

    Thymeleaf简介 什么是Thymeleaf Thymeleaf是网站或者独立应用程序的新式的服务端java模板引擎,可以执行HTML,XML,JavaScript,CSS甚至纯文本模板. Thy ...

随机推荐

  1. [USACO19JAN]Cow Poetry

    题面 Solution: 这是一道很好的dp题. 一开始看不懂题面没有一点思路,看了好久题解才看懂题目... \(y[i]\) 为第 \(i\) 个词结尾,\(l[i]\) 为第 \(i\) 个词长度 ...

  2. [模板]BZOJ4756线段树合并

    题面 Solution: 板子不解释 #include <iostream> #include <algorithm> #include <cstdio> #inc ...

  3. 论文翻译 - Multiagent Bidirectionally-Coordinated Nets Emergence of Human-level Coordination in Learning to Play StarCraft Combat Games

    (缺少一些公式的图或者效果图,评论区有惊喜) (个人学习这篇论文时进行的翻译[谷歌翻译,你懂的],如有侵权等,请告知) Multiagent Bidirectionally-Coordinated N ...

  4. pta指针作业

    #PTA实验作业 6-1 本题pta提交列表 设计思路 本题是一道简单的指针程序题,两个数已经分别被指针定义,只要把用其指针把二者加在一起和减去即可 调试过程 本题无调试过程 代码截图 6-2  1. ...

  5. 【Linux】- ls命令详解

    1 命令功能: 列出当前目录下或者指定目录下的所有文件和目录,ls是list的缩写. 2 命令语法: ls [选项] [目录名]     #注:[]中的内容为非必选项 3 命令选项: -a 列出目录下 ...

  6. phpquery中文手册

    [简介] phpQuery是一个基于PHP的服务端开源项目,它可以让PHP开发人员轻松处理DOM文档内容.更有意思的是,它采用了jQuery的思想,使得可以像使用jQuery一样处理页面内容,获取想要 ...

  7. EF to linq 左连接

    如果连接的数据不存在用 null 表示,则可以左连接查询,但是如果数据类型为 int 则会出错. var ng = (from g in _db.NET_NEWS_GROUP join z in _d ...

  8. 开发一个delphi写的桌面图标管理代码

    参加工作了就很少有时间去玩delphi了,这个适合初学者看看,大神勿喷 工具 delhpi7.0 access数据库 原则win下有安装office就可用 当初不太熟悉sqlite所有没用这做数据库. ...

  9. Spring之JDBC

    jdbc.properties driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/ssi?useUnicode ...

  10. dp类模板

    1.n串最长公共子序列 #include<cstdio> #include<cstring> #include<algorithm> using namespace ...