Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夏至溪檐
dr_py
提交
9bc624d3
dr_py
项目概览
夏至溪檐
/
dr_py
与 Fork 源项目一致
Fork自
晚风拂柳颜 / dr_py
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
dr_py
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9bc624d3
编写于
11月 17, 2022
作者:
H
hjdhnx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
js0语法优化,支持元素排除
上级
a9d6317a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
9 addition
and
8 deletion
+9
-8
utils/htmlParser.py
utils/htmlParser.py
+9
-8
未找到文件。
utils/htmlParser.py
浏览文件 @
9bc624d3
...
...
@@ -15,6 +15,7 @@ PARSE_CACHE = True # 解析缓存
NOADD_INDEX
=
':eq|:lt|:gt|:first|:last|^body$|^#'
# 不自动加eq下标索引
URLJOIN_ATTR
=
'(url|src|href|-original|-src|-play|-url)$'
# 需要自动urljoin的属性
class
jsoup
:
def
__init__
(
self
,
MY_URL
=
''
):
self
.
MY_URL
=
MY_URL
...
...
@@ -62,7 +63,7 @@ class jsoup:
return
parse
def
getParseInfo
(
self
,
nparse
):
def
getParseInfo
(
self
,
nparse
):
"""
根据传入的单规则获取 parse规则,索引位置,排除列表 -- 可以用于剔除元素,支持多个,按标签剔除,按id剔除等操作
:param nparse:
...
...
@@ -70,7 +71,7 @@ class jsoup:
"""
excludes
=
[]
# 定义排除列表默认值为空
nparse_index
=
0
# 定义位置索引默认值为0
nparse_rule
=
nparse
# 定义规则默认值为本身
nparse_rule
=
nparse
# 定义规则默认值为本身
if
self
.
test
(
':eq'
,
nparse
):
nparse_rule
=
nparse
.
split
(
':eq'
)[
0
]
nparse_pos
=
nparse
.
split
(
':eq'
)[
1
]
...
...
@@ -88,7 +89,7 @@ class jsoup:
nparse_index
=
0
if
nparse_index
>
0
:
print
(
f
'nparse_rule:
{
nparse_rule
}
,nparse_index:
{
nparse_index
}
,excludes:
{
excludes
}
'
)
return
nparse_rule
,
nparse_index
,
excludes
return
nparse_rule
,
nparse_index
,
excludes
else
:
if
self
.
test
(
'--'
,
nparse
):
nparse_rule
=
nparse
.
split
(
'--'
)[
0
]
...
...
@@ -115,7 +116,7 @@ class jsoup:
# if nparse_index > 4:
# print('2nparse_index',ret)
if
excludes
and
ret
:
ret
=
ret
.
clone
()
# 克隆一个,免得直接remove会影响doc的缓存
ret
=
ret
.
clone
()
# 克隆一个,免得直接remove会影响doc的缓存
for
exclude
in
excludes
:
ret
.
remove
(
exclude
)
else
:
...
...
@@ -125,7 +126,7 @@ class jsoup:
else
:
ret
=
ret
(
nparse_rule
)
if
excludes
and
ret
:
ret
=
ret
.
clone
()
# 克隆一个,免得直接remove会影响doc的缓存
ret
=
ret
.
clone
()
# 克隆一个,免得直接remove会影响doc的缓存
for
exclude
in
excludes
:
ret
.
remove
(
exclude
)
return
ret
...
...
@@ -150,7 +151,7 @@ class jsoup:
ret
=
None
for
nparse
in
parses
:
ret
=
self
.
parseOneRule
(
doc
,
nparse
,
ret
)
if
not
ret
:
# 可能循环取值后ret 对应eq取完无值了,pdfa直接返回空列表
if
not
ret
:
# 可能循环取值后ret 对应eq取完无值了,pdfa直接返回空列表
return
[]
res
=
[
item
.
outerHtml
()
for
item
in
ret
.
items
()]
return
res
...
...
@@ -183,7 +184,7 @@ class jsoup:
for
nparse
in
parses
:
ret
=
self
.
parseOneRule
(
doc
,
nparse
,
ret
)
# print(nparse,ret)
if
not
ret
:
# 可能循环取值后ret 对应eq取完无值了,pdfh直接返回空字符串
if
not
ret
:
# 可能循环取值后ret 对应eq取完无值了,pdfh直接返回空字符串
return
''
if
option
:
...
...
@@ -270,4 +271,4 @@ class jsoup:
if
__name__
==
'__main__'
:
pass
\ No newline at end of file
pass
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录