Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wchjxyzj
dr_py
提交
c25b87f1
D
dr_py
项目概览
wchjxyzj
/
dr_py
与 Fork 源项目一致
Fork自
晚风拂柳颜 / dr_py
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dr_py
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c25b87f1
编写于
8月 29, 2022
作者:
H
hjdhnx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
我又牛逼了
上级
275776e5
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
6283 addition
and
27 deletion
+6283
-27
app.py
app.py
+10
-8
classes/cms.py
classes/cms.py
+5
-9
js/蓝莓影视.js
js/蓝莓影视.js
+1
-1
models/rules.db
models/rules.db
+0
-0
readme.md
readme.md
+3
-0
requirements.txt
requirements.txt
+1
-1
txt/issue.txt
txt/issue.txt
+15
-0
txt/libs.txt
txt/libs.txt
+2
-1
utils/crypto-js.js
utils/crypto-js.js
+6191
-0
utils/parser.py
utils/parser.py
+46
-5
utils/safePython.py
utils/safePython.py
+1
-1
utils/web.py
utils/web.py
+8
-1
未找到文件。
app.py
浏览文件 @
c25b87f1
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
# File : app.py
# File : app.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date : 2022/8/25
# Date : 2022/8/25
import
time
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_sqlalchemy
import
SQLAlchemy
import
config
import
config
...
@@ -78,19 +77,22 @@ def vod():
...
@@ -78,19 +77,22 @@ def vod():
msg
=
f
'服务端本地仅支持以下规则:
{
","
.
join
(
rule_list
)
}
'
msg
=
f
'服务端本地仅支持以下规则:
{
","
.
join
(
rule_list
)
}
'
return
jsonify
(
error
.
failed
(
msg
))
return
jsonify
(
error
.
failed
(
msg
))
t1
=
time
.
time
()
t1
=
time
()
js_path
=
f
'js/
{
rule
}
.js'
if
not
ext
.
startswith
(
'http'
)
else
ext
js_path
=
f
'js/
{
rule
}
.js'
if
not
ext
.
startswith
(
'http'
)
else
ext
# before = ''
with
open
(
'js/模板.js'
,
encoding
=
'utf-8'
)
as
f
:
with
open
(
'js/模板.js'
,
encoding
=
'utf-8'
)
as
f
:
before
=
f
.
read
()
before
=
f
.
read
()
# print(before)
logger
.
info
(
f
'js读取耗时:
{
get_interval
(
t1
)
}
毫秒'
)
ctx
,
js_code
=
parser
.
runJs
(
js_path
,
before
=
before
)
t2
=
time
()
ctx
,
js_code
=
parser
.
runJs
(
js_path
,
before
=
before
)
if
not
js_code
:
if
not
js_code
:
return
jsonify
(
error
.
failed
(
'爬虫规则加载失败'
))
return
jsonify
(
error
.
failed
(
'爬虫规则加载失败'
))
rule
=
ctx
.
eval
(
'rule'
)
# rule = ctx.eval('rule')
t2
=
time
.
time
()
rule
=
ctx
.
rule
.
to_dict
()
logger
.
info
(
f
'js装载耗时:
{
round
((
t2
-
t1
)
*
1000
,
2
)
}
毫秒'
)
# print(rule)
# print(type(rule))
logger
.
info
(
f
'js装载耗时:
{
get_interval
(
t2
)
}
毫秒'
)
# print(rule)
# print(rule)
cms
=
CMS
(
rule
,
db
,
RuleClass
,
PlayParse
,
app
.
config
)
cms
=
CMS
(
rule
,
db
,
RuleClass
,
PlayParse
,
app
.
config
)
wd
=
getParmas
(
'wd'
)
wd
=
getParmas
(
'wd'
)
...
...
classes/cms.py
浏览文件 @
c25b87f1
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
# File : cms.py
# File : cms.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date : 2022/8/25
# Date : 2022/8/25
import
execjs
import
requests
import
requests
import
re
import
re
import
math
import
math
...
@@ -16,7 +16,6 @@ from utils.parser import runPy
...
@@ -16,7 +16,6 @@ from utils.parser import runPy
from
utils.htmlParser
import
jsoup
from
utils.htmlParser
import
jsoup
from
urllib.parse
import
urljoin
from
urllib.parse
import
urljoin
from
concurrent.futures
import
ThreadPoolExecutor
# 引入线程池
from
concurrent.futures
import
ThreadPoolExecutor
# 引入线程池
from
time
import
time
from
flask
import
url_for
,
redirect
from
flask
import
url_for
,
redirect
from
easydict
import
EasyDict
as
edict
from
easydict
import
EasyDict
as
edict
...
@@ -277,10 +276,9 @@ class CMS:
...
@@ -277,10 +276,9 @@ class CMS:
# print(self.class_parse)
# print(self.class_parse)
try
:
try
:
if
self
.
class_parse
:
if
self
.
class_parse
:
t
3
=
time
()
t
2
=
time
()
cache_classes
=
self
.
getClasses
()
cache_classes
=
self
.
getClasses
()
t4
=
time
()
logger
.
info
(
f
'
{
self
.
getName
()
}
读取缓存耗时:
{
get_interval
(
t2
)
}
毫秒'
)
logger
.
info
(
f
'
{
self
.
getName
()
}
读取缓存耗时:
{
round
((
t4
-
t3
)
*
1000
,
2
)
}
毫秒'
)
if
len
(
cache_classes
)
>
0
:
if
len
(
cache_classes
)
>
0
:
classes
=
cache_classes
classes
=
cache_classes
# print(cache_classes)
# print(cache_classes)
...
@@ -325,8 +323,7 @@ class CMS:
...
@@ -325,8 +323,7 @@ class CMS:
if
self
.
filter
:
if
self
.
filter
:
result
[
'filters'
]
=
config
[
'filter'
]
result
[
'filters'
]
=
config
[
'filter'
]
result
.
update
(
video_result
)
result
.
update
(
video_result
)
t2
=
time
()
logger
.
info
(
f
'
{
self
.
getName
()
}
获取首页总耗时(包含读取缓存):
{
get_interval
(
t1
)
}
毫秒'
)
logger
.
info
(
f
'
{
self
.
getName
()
}
获取首页耗时:
{
round
((
t2
-
t1
)
*
1000
,
2
)
}
毫秒'
)
return
result
return
result
def
homeVideoContent
(
self
,
html
,
fypage
=
1
):
def
homeVideoContent
(
self
,
html
,
fypage
=
1
):
...
@@ -569,8 +566,7 @@ class CMS:
...
@@ -569,8 +566,7 @@ class CMS:
result
=
{
result
=
{
'list'
:
vod_list
'list'
:
vod_list
}
}
t2
=
time
()
logger
.
info
(
f
'
{
self
.
getName
()
}
获取详情页耗时:
{
get_interval
(
t1
)
}
毫秒,共计
{
round
(
len
(
str
(
result
))
/
1000
,
2
)
}
kb'
)
logger
.
info
(
f
'
{
self
.
getName
()
}
获取详情页耗时:
{
round
((
t2
-
t1
)
*
1000
,
2
)
}
毫秒,共计
{
round
(
len
(
str
(
result
))
/
1000
,
2
)
}
kb'
)
# print(result)
# print(result)
return
result
return
result
...
...
js/蓝莓影视.js
浏览文件 @
c25b87f1
var
rule
=
{
var
rule
=
{
title
:
'
蓝莓影视
'
,
title
:
'
蓝莓影视
1
'
,
host
:
'
https://lanmeiguojiang.com
'
,
host
:
'
https://lanmeiguojiang.com
'
,
// homeUrl:'/',
// homeUrl:'/',
url
:
'
/show/fyclass--------fypage---.html
'
,
url
:
'
/show/fyclass--------fypage---.html
'
,
...
...
models/rules.db
浏览文件 @
c25b87f1
无法预览此类型文件
readme.md
浏览文件 @
c25b87f1
#### dr模板的python实现
#### dr模板的python实现
###### 更新日志
###### 更新日志
###### 2022/08/29
-
[X] 1.更换js引擎,速度更快性能更好
-
[X] 2.新版js支持与python互动,后期可能支持js免嗅(lazy:'@js:xxx')
###### 2022/08/28
###### 2022/08/28
-
[X] 1.增加linux进程启动,命令 supervisord -c manager.conf
-
[X] 1.增加linux进程启动,命令 supervisord -c manager.conf
-
[X] 2.转移文本文件到txt目录
-
[X] 2.转移文本文件到txt目录
...
...
requirements.txt
浏览文件 @
c25b87f1
PyExecJS
js2py
pyquery
pyquery
flask
flask
requests
requests
...
...
txt/issue.txt
0 → 100644
浏览文件 @
c25b87f1
错误:Could not link required node_modules
解决:在Python包安装路径下的js2py/node_import.py的17行有以下代码
assert subprocess.call(
'cd %s;npm install babel-core babel-cli babel-preset-es2015 babel-polyfill babelify browserify browserify-shim'
% repr(DIRNAME),
shell=True,
cwd=DIRNAME) == 0, 'Could not link required node_modules'
修改为
assert subprocess.call(
'npm install babel-core babel-cli babel-preset-es2015 babel-polyfill babelify browserify browserify-shim',
shell=True,
cwd=DIRNAME) == 0, 'Could not link required node_modules'
txt/libs.txt
浏览文件 @
c25b87f1
gevent-websocket
gevent-websocket
\ No newline at end of file
PyExecJS
\ No newline at end of file
utils/crypto-js.js
0 → 100644
浏览文件 @
c25b87f1
此差异已折叠。
点击以展开。
utils/parser.py
浏览文件 @
c25b87f1
...
@@ -7,21 +7,24 @@
...
@@ -7,21 +7,24 @@
import
os
import
os
import
requests
import
requests
from
flask
import
make_response
,
jsonify
from
flask
import
make_response
,
jsonify
from
functools
import
partial
# 这玩意儿能锁定一个函数的参数
from
functools
import
partial
# 这玩意儿能锁定一个函数的参数
import
subprocess
import
subprocess
subprocess
.
Popen
=
partial
(
subprocess
.
Popen
,
encoding
=
"utf-8"
)
# 固定写法
subprocess
.
Popen
=
partial
(
subprocess
.
Popen
,
encoding
=
"utf-8"
)
# 固定写法
# 解决execjs执行js时产生的乱码报错,需要在导入该模块之前,让Popen的encoding参数锁定为utf-8
# 解决execjs执行js时产生的乱码报错,需要在导入该模块之前,让Popen的encoding参数锁定为utf-8
import
execjs
# import execjs
import
js2py
# os.environ["EXECJS_RUNTIME"] = "JScript"
# os.environ["EXECJS_RUNTIME"] = "JScript"
# print(execjs.get().name)
# print(execjs.get().name)
def
runJs
(
jsPath
,
before
=
''
,
after
=
''
):
def
runJs
(
jsPath
,
before
=
''
,
after
=
''
,
ctx
=
None
):
# base_path = os.path.dirname(os.path.abspath(__file__)) # 当前文件所在目录
# base_path = os.path.dirname(os.path.abspath(__file__)) # 当前文件所在目录
# base_path = os.path.dirname(os.getcwd()) # 当前主程序所在工作目录
# base_path = os.path.dirname(os.getcwd()) # 当前主程序所在工作目录
# base_path = os.path.dirname(os.path.abspath('.')) # 上级目录
# base_path = os.path.dirname(os.path.abspath('.')) # 上级目录
# js_code = 'var rule={}'
# js_code = 'var rule={}'
if
ctx
is
None
:
ctx
=
{}
base_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
)))
# 上级目录
base_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
)))
# 上级目录
if
str
(
jsPath
).
startswith
(
'http'
):
if
str
(
jsPath
).
startswith
(
'http'
):
js_name
=
jsPath
.
split
(
'/'
)[
-
1
]
js_name
=
jsPath
.
split
(
'/'
)[
-
1
]
...
@@ -48,7 +51,9 @@ def runJs(jsPath,before='',after=''):
...
@@ -48,7 +51,9 @@ def runJs(jsPath,before='',after=''):
jscode_to_run
=
before
+
jscode_to_run
jscode_to_run
=
before
+
jscode_to_run
if
after
:
if
after
:
jscode_to_run
+=
after
jscode_to_run
+=
after
loader
=
execjs
.
compile
(
jscode_to_run
)
loader
=
js2py
.
EvalJs
(
ctx
)
# loader = execjs.compile(jscode_to_run)
loader
.
execute
(
jscode_to_run
)
return
loader
,
js_code
return
loader
,
js_code
def
toJs
(
jsPath
):
def
toJs
(
jsPath
):
...
@@ -104,4 +109,40 @@ def runPy(pyPath):
...
@@ -104,4 +109,40 @@ def runPy(pyPath):
with
open
(
py_path
,
'r'
,
encoding
=
'UTF-8'
)
as
fp
:
with
open
(
py_path
,
'r'
,
encoding
=
'UTF-8'
)
as
fp
:
py_code
=
fp
.
read
()
py_code
=
fp
.
read
()
# print(js_code)
# print(js_code)
return
py_code
return
py_code
\ No newline at end of file
def
covert_demo
():
ctx
=
{
'py_sum'
:
sum
,
'requests'
:
requests
}
loader
=
js2py
.
EvalJs
(
ctx
)
# loader.execute('var a=py_sum(2,3);function f(x) {return x*x} var b=[a,"5"];var c={"a":a};')
# loader.execute('var a=py_sum(2,3);function f(x) {return x*x}')
loader
.
execute
(
'function f(x) {return x*x};var a=py_sum([2,3]);var b=[a,5];var c={"a":a};'
)
f
=
loader
.
f
print
(
f
(
8
))
print
(
loader
.
eval
(
'py_sum(new Array(1, 2, 3))'
))
print
(
loader
.
eval
(
'py_sum([1, 2])'
))
a
=
loader
.
a
print
(
type
(
a
),
a
)
b
=
loader
.
b
b
.
push
(
6
)
print
(
type
(
b
),
b
)
b
=
b
.
to_list
()
print
(
type
(
b
),
b
)
c
=
loader
.
c
print
(
type
(
c
),
c
)
c
=
c
.
to_dict
()
print
(
type
(
c
),
c
)
# CryptoJS = js2py.require('crypto-js')
# print(type(CryptoJS))
# print(js2py.require('underscore'))
JSON
=
js2py
.
eval_js
(
'JSON'
)
r
=
JSON
.
parse
(
'[{"a":1}]'
)
print
(
type
(
r
),
r
)
print
(
r
[
0
].
a
)
print
(
loader
.
eval
(
'r = requests.get("https://www.baidu.com/");r.encoding = "utf-8";r.text'
))
# 下面是错误用法,没有loader环境没法正确eval_js,有loader用eval不需要eval_js
print
(
js2py
.
eval_js
(
'r = requests.get("https://www.baidu.com/");r.encoding = "utf-8";r.text'
))
if
__name__
==
'__main__'
:
covert_demo
()
\ No newline at end of file
utils/safePython.py
浏览文件 @
c25b87f1
...
@@ -19,7 +19,7 @@ import datetime
...
@@ -19,7 +19,7 @@ import datetime
import
base64
import
base64
from
utils.log
import
logger
from
utils.log
import
logger
time_out_sec
=
8
time_out_sec
=
8
# 安全执行python代码超时
class
my_exception
(
Exception
):
class
my_exception
(
Exception
):
def
__init__
(
self
,
message
):
def
__init__
(
self
,
message
):
self
.
message
=
message
self
.
message
=
message
...
...
utils/web.py
浏览文件 @
c25b87f1
...
@@ -17,6 +17,8 @@ headers = {
...
@@ -17,6 +17,8 @@ headers = {
'Referer'
:
'https://www.baidu.com'
,
'Referer'
:
'https://www.baidu.com'
,
'user-agent'
:
UA
,
'user-agent'
:
UA
,
}
}
from
time
import
time
def
get_host_ip2
():
# 获取局域网ip
def
get_host_ip2
():
# 获取局域网ip
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
try
:
try
:
...
@@ -63,4 +65,9 @@ def get_conf(obj):
...
@@ -63,4 +65,9 @@ def get_conf(obj):
if
key
.
isupper
():
if
key
.
isupper
():
new_conf
[
key
]
=
getattr
(
obj
,
key
)
new_conf
[
key
]
=
getattr
(
obj
,
key
)
# print(new_conf)
# print(new_conf)
return
new_conf
return
new_conf
\ No newline at end of file
def
get_interval
(
t
):
interval
=
time
()
-
t
interval
=
round
(
interval
*
1000
,
2
)
return
interval
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录