Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
783b7172
提交
783b7172
authored
11月 29, 2023
作者:
薛凌堃
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
11.29
上级
fa46345c
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
89 行增加
和
40 行删除
+89
-40
LawRules-shenzhen.py
REITs专题数据/LawRules-shenzhen.py
+89
-40
没有找到文件。
REITs专题数据/LawRules-shenzhen.py
浏览文件 @
783b7172
impor
t
os
impor
t
os
...
...
@@ -2,18 +2,23 @@ import os
import
time
from
urllib.parse
import
urljoin
import
numpy
as
np
import
pandas
as
pd
import
requests
from
bs4
import
BeautifulSoup
from
selenium.webdriver.common.by
import
By
from
base
import
BaseCore
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support
import
expected_conditions
as
EC
import
BaseCore
baseCore
=
BaseCore
.
BaseCore
()
log
=
baseCore
.
getLogger
()
from
reits
import
Policy
policy
=
Policy
()
topic
=
'policy'
webname
=
'深圳证券交易所'
headers
=
{
'Accept'
:
'application/json, text/javascript, */*; q=0.01'
,
'Accept-Encoding'
:
'gzip, deflate'
,
...
...
@@ -57,9 +62,8 @@ def getFjContent(url):
return
content
def
getContent
(
url
,
publishDate
,
num
):
fjhref_list
=
''
fjtitle_list
=
''
def
getContent
(
url
,
publishDate
,
num
,
id_list
):
num
+=
1
ip
=
baseCore
.
get_proxy
()
req
=
requests
.
get
(
url
,
headers
=
headers
,
proxies
=
ip
)
req
.
encoding
=
req
.
apparent_encoding
...
...
@@ -67,27 +71,23 @@ def getContent(url, publishDate, num):
soup
=
paserUrl
(
soup
,
'http://www.szse.cn/'
)
contentWithTag
=
soup
.
find
(
'div'
,
class_
=
'des-content'
)
a_list
=
contentWithTag
.
find_all
(
'a'
)
num_
=
1
for
a
in
a_list
:
fj_href
=
a
.
get
(
'href'
)
if
not
fj_href
:
continue
fjhref_list
+=
fj_href
+
'
\n
'
fj_title
=
a
.
text
.
lstrip
()
.
strip
()
category
=
os
.
path
.
splitext
(
fj_href
)[
1
]
if
category
not
in
fj_title
:
fj_title
=
fj_title
+
category
fj_title
=
f
'{num}-{publishDate}-{fj_title}'
fjcontent
=
getFjContent
(
fj_href
)
file
=
f
'./相关政策/深圳证券交易所/政策文件/{fj_title}'
if
os
.
path
.
exists
(
file
):
fj_title
=
fj_title
.
replace
(
category
,
f
'-{num_}{category}'
)
num_
+=
1
file
=
f
'./相关政策/深圳证券交易所/政策文件/{fj_title}'
fjtitle_list
+=
fj_title
+
'
\n
'
with
open
(
file
,
'wb'
)
as
f
:
f
.
write
(
fjcontent
)
log
.
info
(
f
'{fj_title}===附件下载成功'
)
# 上传附件至obs
att_id
,
full_path
=
policy
.
attuributefile
(
fj_title
,
fj_href
,
num
,
publishDate
)
if
att_id
:
id_list
.
append
(
att_id
)
a
[
'href'
]
=
full_path
try
:
scripts
=
contentWithTag
.
find_all
(
'script'
)
for
script
in
scripts
:
...
...
@@ -102,14 +102,14 @@ def getContent(url, publishDate, num):
pass
pub_hao
=
contentWithTag
.
find
(
'p'
)
.
text
.
lstrip
()
.
strip
()
content
=
contentWithTag
.
text
.
lstrip
()
.
strip
()
return
pub_hao
,
content
,
fjtitle_list
,
fjhref_list
return
pub_hao
,
content
,
id_list
,
contentWithTag
def
doJob
():
if
not
os
.
path
.
exists
(
'./相关政策/深圳证券交易所/政策文件'
):
os
.
makedirs
(
'./相关政策/深圳证券交易所/政策文件'
)
#
if not os.path.exists('./相关政策/深圳证券交易所/政策文件'):
#
os.makedirs('./相关政策/深圳证券交易所/政策文件')
url
=
'http://www.szse.cn/lawrules/search/index.html?rulekeyword=REITs&channelCode=
%5
B
%22
rules
%22
,
%22
csrcrules
%22
,
%22
szseBussrules
%22
,
%22
memorandumServicedirect
%22
,
%22
publicadvice
%22
,
%22
lawruleSearch
%22%5
D&range=content&searchtype=0'
driver
=
baseCore
.
build
Driver
()
driver
=
policy
.
create
Driver
()
driver
.
get
(
url
)
WebDriverWait
(
driver
,
10
)
.
until
(
EC
.
presence_of_element_located
((
By
.
CLASS_NAME
,
'article-item'
))
...
...
@@ -118,35 +118,84 @@ def doJob():
num
=
0
data_list
=
[]
for
div
in
div_list
:
id_list
=
[]
title
=
div
.
find_element
(
By
.
TAG_NAME
,
'a'
)
.
text
.
lstrip
()
.
strip
()
href
=
div
.
find_element
(
By
.
TAG_NAME
,
'a'
)
.
get_attribute
(
'href'
)
publishDate
=
div
.
find_element
(
By
.
CLASS_NAME
,
'pull-right'
)
.
text
.
lstrip
()
.
strip
()
writtenDate
=
publishDate
origin
=
'深圳证券交易所'
organ
=
origin
# 文章就为pdf
# 根据链接判重
is_member
=
baseCore
.
r
.
sismember
(
'REITs::'
+
webname
,
href
)
if
is_member
:
continue
if
'.pdf'
in
href
:
content
=
''
summary
=
''
fjtitle_list
=
title
+
'.pdf'
fjhref_list
=
href
pub_hao
=
''
fjcontent
=
getFjContent
(
href
)
file
=
f
'./相关政策/深圳证券交易所/政策文件/{title}.pdf'
with
open
(
file
,
'wb'
)
as
f
:
f
.
write
(
fjcontent
)
log
.
info
(
f
'{title}===附件下载成功'
)
time_now
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
())
dic_info
=
{
'attachmentIds'
:
id_list
,
'author'
:
''
,
'content'
:
fjcontent
,
'contentWithTag'
:
''
,
'deleteFlag'
:
0
,
'id'
:
''
,
'title'
:
title
,
'publishDate'
:
publishDate
,
'origin'
:
origin
,
'sourceAddress'
:
href
,
'writtenDate'
:
writtenDate
,
'organ'
:
organ
,
'topicClassification'
:
''
,
'issuedNumber'
:
pub_hao
,
'summary'
:
summary
,
'createDate'
:
time_now
,
'sid'
:
'1729029275400646658'
,
}
try
:
baseCore
.
sendkafka
(
dic_info
,
topic
)
baseCore
.
r
.
sadd
(
'REITs::'
+
webname
,
href
)
log
.
info
(
f
'采集成功--{title}--{href}'
)
except
:
for
att_id
in
id_list
:
baseCore
.
deliteATT
(
att_id
)
else
:
summary
=
div
.
find_element
(
By
.
CLASS_NAME
,
'item-content'
)
.
text
.
lstrip
()
.
strip
()
pub_hao
,
content
,
fjtitle_list
,
fjhref_list
=
getContent
(
href
,
publishDate
,
num
)
data
=
[
num
,
title
,
publishDate
,
origin
,
href
,
writtenDate
,
organ
,
pub_hao
,
summary
,
content
,
fjtitle_list
,
fjhref_list
]
data_list
.
append
(
data
)
log
.
info
(
f
'{title}===采集成功'
)
num
+=
1
pub_hao
,
content
,
id_list
,
contentWithTag
=
getContent
(
href
,
publishDate
,
num
,
id_list
)
time_now
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
())
dic_info
=
{
'attachmentIds'
:
id_list
,
'author'
:
''
,
'content'
:
content
,
'contentWithTag'
:
str
(
contentWithTag
),
'deleteFlag'
:
0
,
'id'
:
''
,
'title'
:
title
,
'publishDate'
:
publishDate
,
'origin'
:
origin
,
'sourceAddress'
:
href
,
'writtenDate'
:
writtenDate
,
'organ'
:
organ
,
'topicClassification'
:
''
,
'issuedNumber'
:
pub_hao
,
'summary'
:
summary
,
'createDate'
:
time_now
,
'sid'
:
'1729029275400646658'
,
}
try
:
baseCore
.
sendkafka
(
dic_info
,
topic
)
baseCore
.
r
.
sadd
(
'REITs::'
+
webname
,
href
)
log
.
info
(
f
'采集成功--{title}--{href}'
)
except
:
for
att_id
in
id_list
:
baseCore
.
deliteATT
(
att_id
)
driver
.
close
()
df
=
pd
.
DataFrame
(
np
.
array
(
data_list
))
df
.
columns
=
[
'序号'
,
'标题'
,
'发布时间'
,
'来源'
,
'原文链接'
,
'发文时间'
,
'发文机构'
,
'发文字号'
,
'摘要'
,
'正文'
,
'附件名称'
,
'附件连接'
]
df
.
to_excel
(
'./相关政策/深圳证券交易所/深圳证券交易所政策文件.xlsx'
,
index
=
False
)
#
df = pd.DataFrame(np.array(data_list))
#
df.columns = ['序号', '标题', '发布时间', '来源', '原文链接', '发文时间', '发文机构', '发文字号', '摘要', '正文', '附件名称', '附件连接']
#
df.to_excel('./相关政策/深圳证券交易所/深圳证券交易所政策文件.xlsx', index=False)
if
__name__
==
'__main__'
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论