Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
丁双波
zzsn_spider
Commits
6fc56b71
提交
6fc56b71
authored
10月 18, 2024
作者:
XveLingKun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
元搜索修改
上级
2c80eba5
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
30 行增加
和
6 行删除
+30
-6
baiduSpider.py
百度采集/baidu_comm/baiduSpider.py
+3
-3
smart_extractor.py
百度采集/baidu_comm/smart_extractor.py
+25
-2
smart_extractor_utility.py
百度采集/baidu_comm/smart_extractor_utility.py
+2
-1
没有找到文件。
百度采集/baidu_comm/baiduSpider.py
浏览文件 @
6fc56b71
#codi
ng=utf-8
#codi
ng=utf-8
...
...
@@ -420,7 +420,7 @@ class BaiduSpider(object):
lang
=
self
.
detect_language
(
title
)
raw_html
=
self
.
webDriver
(
url
)
sm
=
SmartExtractor
(
lang
)
article
=
sm
.
extract_by_html
(
raw_html
)
article
=
sm
.
extract_by_html
(
raw_html
,
title
)
#todo:标题获取全部标题
title
=
article
.
title
content
=
article
.
cleaned_text
...
...
@@ -429,7 +429,7 @@ class BaiduSpider(object):
try
:
raw_html
=
self
.
webDriver
(
url
)
sm
=
SmartExtractor
(
lang
)
article
=
sm
.
extract_by_html
(
raw_html
)
article
=
sm
.
extract_by_html
(
raw_html
,
title
)
# todo:标题获取全部标题
title
=
article
.
title
content
=
article
.
cleaned_text
...
...
百度采集/baidu_comm/smart_extractor.py
浏览文件 @
6fc56b71
# -*
- coding: utf-8 -*-
# -*
- coding: utf-8 -*-
...
...
@@ -129,8 +129,31 @@ class SmartExtractor:
"""
按HTML采集内容
"""
#todo 1018去除head标签 将textarea标签替换成div标签
from
bs4
import
BeautifulSoup
html_
=
BeautifulSoup
(
html
,
'html.parser'
)
head_tag
=
html_
.
find
(
'head'
)
if
head_tag
:
head_tag
.
decompose
()
aside_tag
=
html_
.
find
(
'aside'
)
if
aside_tag
:
aside_tag
.
decompose
()
textarea_tags
=
html_
.
find_all
(
'textarea'
)
if
textarea_tags
:
for
textarea
in
textarea_tags
:
try
:
# 创建一个新的 <div> 标签
div_tag
=
html_
.
new_tag
(
'div'
)
# 将 <textarea> 的内容移动到新的 <div> 标签中
div_tag
.
string
=
textarea
.
string
# 替换 <textarea> 标签
textarea
.
replace_with
(
div_tag
)
except
Exception
as
e
:
continue
# 采集正文:传入html
article
=
self
.
goose
.
extract
(
raw_html
=
html
)
article
=
self
.
goose
.
extract
(
raw_html
=
str
(
html_
))
# str(html_
)
return
self
.
get_extraction_result
(
article
,
link_text
)
...
...
百度采集/baidu_comm/smart_extractor_utility.py
浏览文件 @
6fc56b71
# -*-
coding: utf-8 -*-
# -*-
coding: utf-8 -*-
...
...
@@ -91,6 +91,7 @@ class SmartExtractorUtility:
'span'
,
'td'
,
'p'
,
'title'
]
# 对比标题前,统一将空格剔除(2022-09-21):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论