pressmuSpiderr
#!/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的更多相关文章
- Thymeleaf3.0内容
Thymeleaf简介 什么是Thymeleaf Thymeleaf是网站或者独立应用程序的新式的服务端java模板引擎,可以执行HTML,XML,JavaScript,CSS甚至纯文本模板. Thy ...
随机推荐
- LB
LB(LBaaS)及Load Balance as a Service是 Neutron 提供的一项高级网络服务. LBaaS 允许租户在自己的网络中创建和管理 load balancer,load ...
- 分布式文件系统---GlusterF
1.1 分布式文件系统 1.1.1 什么是分布式文件系统 相对于本机端的文件系统而言,分布式文件系统(英语:Distributed file system, DFS),或是网络文件系统(英语:Ne ...
- BufferedInputStream/BufferedOutputStream
BufferedInputStream: public synchronized int read() throws IOException int res=bis.read(); System.ou ...
- [android]不解锁刷机
本人因为误操作进入andriod recovery模式,显示failed to boot 2,致手机无法恢复出厂值, 当时那叫一个郁闷.上论坛搜寻无数,唉让刷底包的无数(在此不解释),万恶的刷底包. ...
- iOS版微信开发小结(微信支付,APP跳转微信公众号)
最近公司心血来潮,一心要搞微信.废话不多说,直接上干货. 开发前准备: 1.在微信开发者平台获取开发者认证:(一年300元人民币) PS:具体流程按照微信流程指示操作即可,在这就不废话了. 2.下载微 ...
- 从零开始配置Jenkins(三)——用户权限管理
背景 最近项目管理中需要对jenkins的权限进行区分和限定,就研究了一下下.顺道把用户和权限这块的内容分享给大家. 用户 要想创建用户,需要先设定允许用户注册. 在系统设置,Configure Gl ...
- SSH Secure Shell Client的使用方法
1:双击其客户端图标,出现下图所示窗体 2:我使用她主要用于发布项目的,所以第一次使用会选择新建一个账户 3:填写账户的名称 4:完善账户的信息 5:主要用填下远程主机的IP/USER/PORT,在需 ...
- 使用 TListView 控件(2)
本例效果图: 代码文件: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, ...
- iOS-数据持久化之Sqllite
iOS中的数据存储方式 Plist(NSArray\NSDictionary) Preference(偏好设置\NSUserDefaults) NSCoding(NSKeyedArchiver\NSk ...
- 【bzoj3856】Monster 乱搞
题目描述 你要打一只h点血的怪物,每回合你攻击会造成a点伤害,回合结束后怪物会回b点血,你每攻击k回合需要休息一次,该回合不能造成伤害.怪物血量降到0以下就会死亡,问最后能否打死怪物. 输入 Ther ...