Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
丁双波
zzsn_spider
Commits
95cfdf3b
提交
95cfdf3b
authored
12月 06, 2023
作者:
薛凌堃
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
云南省人民政府
上级
f7c275d7
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
71 行增加
和
53 行删除
+71
-53
policy-yunnan.py
REITs专题数据/policy-yunnan.py
+71
-53
没有找到文件。
REITs专题数据/policy-yunnan.py
浏览文件 @
95cfdf3b
impor
t
os
impor
t
os
...
...
@@ -10,10 +10,17 @@ from bs4 import BeautifulSoup
from
retry
import
retry
from
selenium.webdriver.common.by
import
By
from
base
import
BaseCore
import
BaseCore
baseCore
=
BaseCore
.
BaseCore
()
log
=
baseCore
.
getLogger
()
from
reits
import
Policy
policy
=
Policy
()
topic
=
'policy'
webname
=
'云南省人民政府'
headers
=
{
'User-Agent'
:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0'
,
}
...
...
@@ -36,9 +43,9 @@ def getFjContent(url):
def
getContent
(
url
,
publishDate
,
num
):
fjhref_list
=
''
fjtitle_list
=
''
id_list
=
[]
soup
=
getSoup
(
url
)
policy
.
paserUrl
(
soup
,
url
)
contentWithTag
=
soup
.
find
(
'div'
,
class_
=
'content'
)
if
not
contentWithTag
:
contentWithTag
=
soup
.
find
(
'div'
,
class_
=
'TRS_UEDITOR'
)
...
...
@@ -62,24 +69,18 @@ def getContent(url, publishDate, num):
fj_href
=
a
.
get
(
'href'
)
if
'http'
not
in
fj_href
:
fj_href
=
'https://www.yn.gov.cn'
+
fj_href
fjhref_list
+=
fj_href
+
'
\n
'
if
fj_title
==
''
:
fj_title
=
str
(
num_
)
num_
+=
1
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}'
fjtitle_list
+=
fj_title
+
'
\n
'
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}'
with
open
(
file
,
'wb'
)
as
f
:
f
.
write
(
fjcontent
)
log
.
info
(
f
'{fj_title}===附件下载成功'
)
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
:
a_list
=
soup
.
find
(
'ul'
,
class_
=
'apfile'
)
.
find_all
(
'a'
)
for
a
in
a_list
:
...
...
@@ -87,39 +88,38 @@ def getContent(url, publishDate, num):
fj_href
=
a
.
get
(
'href'
)
if
'http'
not
in
fj_href
:
fj_href
=
'https://www.yn.gov.cn'
+
fj_href
fjhref_list
+=
fj_href
+
'
\n
'
if
fj_title
==
''
:
fj_title
=
str
(
num_
)
num_
+=
1
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}'
fjtitle_list
+=
fj_title
+
'
\n
'
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}'
with
open
(
file
,
'wb'
)
as
f
:
f
.
write
(
fjcontent
)
log
.
info
(
f
'{fj_title}===附件下载成功'
)
att_id
,
full_path
=
policy
.
attuributefile
(
fj_title
,
fj_href
,
num
,
publishDate
)
if
att_id
:
id_list
.
append
(
att_id
)
a
[
'href'
]
=
full_path
except
:
pass
return
content
,
fjtitle_list
,
fjhref
_list
return
content
,
contentWithTag
,
id
_list
def
getData
(
div
,
num
):
pattern
=
r"\d{4}-\d{2}-\d{2}"
title
=
div
.
find_element
(
By
.
CLASS_NAME
,
'title'
)
.
find_element
(
By
.
CLASS_NAME
,
'fontlan'
)
.
get_attribute
(
'title'
)
.
lstrip
()
.
strip
()
href
=
div
.
find_element
(
By
.
CLASS_NAME
,
'fontlan'
)
.
get_attribute
(
'href'
)
# 根据链接判重
is_member
=
baseCore
.
r
.
sismember
(
'REITs::'
+
webname
,
href
)
if
is_member
:
return
origin
=
'云南省人民政府'
try
:
publishDate
=
re
.
findall
(
pattern
,
div
.
find_element
(
By
.
CLASS_NAME
,
'content'
)
.
text
)[
0
]
except
:
publishDate
=
''
publishDate
=
None
try
:
organ
=
\
div
.
find_element
(
By
.
CLASS_NAME
,
'rowtab'
)
.
find_elements
(
By
.
TAG_NAME
,
'div'
)[
0
]
.
find_elements
(
By
.
TAG_NAME
,
...
...
@@ -135,30 +135,52 @@ def getData(div, num):
organ
=
''
pub_hao
=
''
summary
=
''
writtenDate
=
''
writtenDate
=
None
if
'.pdf'
in
href
or
'.PDF'
in
href
:
id_list
=
[]
content
=
''
fjhref_list
=
href
contentWithTag_str
=
''
fj_href
=
href
fj_title
=
title
+
'.pdf'
fjcontent
=
getFjContent
(
fjhref_list
)
file
=
f
'./相关政策/云南省人民政府/政策文件/{fj_title}'
with
open
(
file
,
'wb'
)
as
f
:
f
.
write
(
fjcontent
)
log
.
info
(
f
'{fj_title}===附件下载成功'
)
fjtitle_list
=
fj_title
att_id
,
full_path
=
policy
.
attuributefile
(
fj_title
,
fj_href
,
num
,
publishDate
)
if
att_id
:
id_list
.
append
(
att_id
)
else
:
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
]
return
data
content
,
contentWithTag
,
id_list
=
getContent
(
href
,
publishDate
,
num
)
contentWithTag_str
=
str
(
contentWithTag
)
time_now
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
())
dic_info
=
{
'attachmentIds'
:
id_list
,
'author'
:
''
,
'content'
:
content
,
'contentWithTag'
:
contentWithTag_str
,
'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'
:
'1729046848292892673'
,
}
try
:
baseCore
.
sendkafka
(
dic_info
,
topic
)
baseCore
.
r
.
sadd
(
'REITs::'
+
webname
,
href
)
log
.
info
(
f
'采集成功--{title}--{href}'
)
except
Exception
as
e
:
for
att_id
in
id_list
:
baseCore
.
deliteATT
(
att_id
)
return
def
doJob
():
if
not
os
.
path
.
exists
(
'./相关政策/云南省人民政府/政策文件'
):
os
.
makedirs
(
'./相关政策/云南省人民政府/政策文件'
)
data_list
=
[]
url
=
'https://sheng.so-gov.cn/s?siteCode=5300000033&qt=REITs'
driver
=
baseCore
.
build
Driver
()
driver
=
policy
.
create
Driver
()
driver
.
get
(
url
)
time
.
sleep
(
2
)
num
=
1
...
...
@@ -176,17 +198,13 @@ def doJob():
time
.
sleep
(
2
)
div_list
=
driver
.
find_elements
(
By
.
XPATH
,
'//*[@id="results"]/div'
)
for
div
in
div_list
:
data
=
getData
(
div
,
num
)
data_list
.
append
(
data
)
log
.
info
(
f
'{data[1]}===采集成功'
)
getData
(
div
,
num
)
num
+=
1
try
:
driver
.
find_element
(
By
.
CLASS_NAME
,
'pagination'
)
.
find_element
(
By
.
CLASS_NAME
,
'next'
)
.
click
()
except
:
pass
df
=
pd
.
DataFrame
(
np
.
array
(
data_list
))
df
.
columns
=
[
'序号'
,
'标题'
,
'发布时间'
,
'来源'
,
'原文链接'
,
'发文时间'
,
'发文机构'
,
'发文字号'
,
'摘要'
,
'正文'
,
'附件名称'
,
'附件连接'
]
df
.
to_excel
(
'./相关政策/云南省人民政府/云南省人民政府政策文件.xlsx'
,
index
=
False
)
if
__name__
==
'__main__'
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论