Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
ff6db068
提交
ff6db068
authored
12月 05, 2023
作者:
薛凌堃
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
山东省人民政府
上级
5bba0870
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
52 行增加
和
29 行删除
+52
-29
policy-shandong.py
REITs专题数据/policy-shandong.py
+52
-29
没有找到文件。
REITs专题数据/policy-shandong.py
浏览文件 @
ff6db068
impor
t
time
impor
t
time
...
@@ -2,13 +2,17 @@ import time
...
@@ -2,13 +2,17 @@ import time
import
requests
import
requests
from
bs4
import
BeautifulSoup
from
bs4
import
BeautifulSoup
from
base
import
BaseCore
import
os
import
os
import
pandas
as
pd
import
BaseCore
import
numpy
as
np
baseCore
=
BaseCore
.
BaseCore
()
baseCore
=
BaseCore
.
BaseCore
()
log
=
baseCore
.
getLogger
()
log
=
baseCore
.
getLogger
()
from
reits
import
Policy
policy
=
Policy
()
topic
=
'policy'
webname
=
'山东省人民政府'
headers
=
{
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'
,
'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'
,
'X-Requested-With'
:
'XMLHttpRequest'
,
'X-Requested-With'
:
'XMLHttpRequest'
,
...
@@ -55,8 +59,7 @@ def getDataJson(page):
...
@@ -55,8 +59,7 @@ def getDataJson(page):
def
getContent
(
url
,
publishDate
,
num
):
def
getContent
(
url
,
publishDate
,
num
):
fjhref_list
=
''
id_list
=
[]
fjtitle_list
=
''
soup
=
getSoup
(
url
)
soup
=
getSoup
(
url
)
contentWithTag
=
soup
.
find
(
'div'
,
class_
=
'wip_art_con'
)
contentWithTag
=
soup
.
find
(
'div'
,
class_
=
'wip_art_con'
)
a_list
=
contentWithTag
.
find_all
(
'a'
)
a_list
=
contentWithTag
.
find_all
(
'a'
)
...
@@ -65,7 +68,7 @@ def getContent(url, publishDate, num):
...
@@ -65,7 +68,7 @@ def getContent(url, publishDate, num):
fj_href
=
a
.
get
(
'href'
)
fj_href
=
a
.
get
(
'href'
)
if
'http'
not
in
fj_href
:
if
'http'
not
in
fj_href
:
fj_href
=
'http://www.shandong.gov.cn'
+
fj_href
fj_href
=
'http://www.shandong.gov.cn'
+
fj_href
fjhref_list
+=
fj_href
+
'
\n
'
fj_title
=
a
.
text
.
lstrip
()
.
strip
()
.
replace
(
' '
,
''
)
fj_title
=
a
.
text
.
lstrip
()
.
strip
()
.
replace
(
' '
,
''
)
if
fj_title
==
''
:
if
fj_title
==
''
:
fj_title
=
str
(
num_
)
fj_title
=
str
(
num_
)
...
@@ -73,13 +76,10 @@ def getContent(url, publishDate, num):
...
@@ -73,13 +76,10 @@ def getContent(url, publishDate, num):
category
=
os
.
path
.
splitext
(
fj_href
)[
1
]
category
=
os
.
path
.
splitext
(
fj_href
)[
1
]
if
category
not
in
fj_title
:
if
category
not
in
fj_title
:
fj_title
=
fj_title
+
category
fj_title
=
fj_title
+
category
fj_title
=
f
'{num}-{publishDate}-{fj_title}'
att_id
,
full_path
=
policy
.
attuributefile
(
fj_title
,
fj_href
,
num
,
publishDate
)
fjtitle_list
+=
fj_title
+
'
\n
'
if
att_id
:
fjcontent
=
getFjContent
(
fj_href
)
id_list
.
append
(
att_id
)
file
=
f
'./相关政策/山东省人民政府/政策文件/{fj_title}'
a
[
'href'
]
=
full_path
with
open
(
file
,
'wb'
)
as
f
:
f
.
write
(
fjcontent
)
log
.
info
(
f
'{fj_title}===附件下载成功'
)
try
:
try
:
scripts
=
contentWithTag
.
find_all
(
'script'
)
scripts
=
contentWithTag
.
find_all
(
'script'
)
for
script
in
scripts
:
for
script
in
scripts
:
...
@@ -93,13 +93,13 @@ def getContent(url, publishDate, num):
...
@@ -93,13 +93,13 @@ def getContent(url, publishDate, num):
except
:
except
:
pass
pass
content
=
contentWithTag
.
text
.
lstrip
()
.
strip
()
content
=
contentWithTag
.
text
.
lstrip
()
.
strip
()
return
content
,
fjtitle_list
,
fjhref
_list
return
content
,
contentWithTag
,
id
_list
def
getData
(
soup
,
num
):
def
getData
(
soup
,
num
):
origin
=
'山东省人民政府'
origin
=
'山东省人民政府'
organ
=
''
organ
=
''
writtenDate
=
''
writtenDate
=
None
pub_hao
=
''
pub_hao
=
''
try
:
try
:
type
=
soup
.
find
(
'span'
,
class_
=
'szf_lmmc'
)
.
text
type
=
soup
.
find
(
'span'
,
class_
=
'szf_lmmc'
)
.
text
...
@@ -111,6 +111,11 @@ def getData(soup, num):
...
@@ -111,6 +111,11 @@ def getData(soup, num):
-
1
]
.
text
.
lstrip
()
.
strip
()
-
1
]
.
text
.
lstrip
()
.
strip
()
pub_hao
=
soup
.
find
(
'table'
,
class_
=
'szf_xxgk'
)
.
find_all
(
'tr'
)[
1
]
.
find_all
(
'td'
)[
-
1
]
.
text
.
lstrip
()
.
strip
()
pub_hao
=
soup
.
find
(
'table'
,
class_
=
'szf_xxgk'
)
.
find_all
(
'tr'
)[
1
]
.
find_all
(
'td'
)[
-
1
]
.
text
.
lstrip
()
.
strip
()
href
=
soup
.
find
(
'a'
,
class_
=
'szf_url'
)
.
text
.
lstrip
()
.
strip
()
href
=
soup
.
find
(
'a'
,
class_
=
'szf_url'
)
.
text
.
lstrip
()
.
strip
()
# 根据链接判重
is_member
=
baseCore
.
r
.
sismember
(
'REITs::'
+
webname
,
href
)
if
is_member
:
return
publishDate
=
soup
.
find
(
'span'
,
class_
=
'szf_rq'
)
.
text
.
lstrip
()
.
strip
()
publishDate
=
soup
.
find
(
'span'
,
class_
=
'szf_rq'
)
.
text
.
lstrip
()
.
strip
()
else
:
else
:
summary
=
soup
.
find
(
'div'
,
class_
=
'szf_ms'
)
.
text
.
lstrip
()
.
strip
()
summary
=
soup
.
find
(
'div'
,
class_
=
'szf_ms'
)
.
text
.
lstrip
()
.
strip
()
...
@@ -121,16 +126,40 @@ def getData(soup, num):
...
@@ -121,16 +126,40 @@ def getData(soup, num):
summary
=
soup
.
find
(
'div'
,
class_
=
'jcse-news-abs-content'
)
.
text
.
lstrip
()
.
strip
()
summary
=
soup
.
find
(
'div'
,
class_
=
'jcse-news-abs-content'
)
.
text
.
lstrip
()
.
strip
()
href
=
soup
.
find
(
'div'
,
class_
=
'jcse-news-url'
)
.
text
.
lstrip
()
.
strip
()
href
=
soup
.
find
(
'div'
,
class_
=
'jcse-news-url'
)
.
text
.
lstrip
()
.
strip
()
publishDate
=
soup
.
find
(
'span'
,
class_
=
'jcse-news-date'
)
.
text
.
lstrip
()
.
strip
()
publishDate
=
soup
.
find
(
'span'
,
class_
=
'jcse-news-date'
)
.
text
.
lstrip
()
.
strip
()
content
,
fjtitle_list
,
fjhref_list
=
getContent
(
href
,
publishDate
,
num
)
content
,
contentWithTag
,
id_list
=
getContent
(
href
,
publishDate
,
num
)
data
=
[
num
,
title
,
publishDate
,
origin
,
href
,
writtenDate
,
organ
,
pub_hao
,
summary
,
content
,
fjtitle_list
,
fjhref_list
]
contentWithTag_str
=
str
(
contentWithTag
)
return
data
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'
:
'1729043593615560705'
,
}
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
():
def
doJob
():
if
not
os
.
path
.
exists
(
'./相关政策/山东省人民政府/政策文件'
):
os
.
makedirs
(
'./相关政策/山东省人民政府/政策文件'
)
data_list
=
[]
num
=
1
num
=
1
for
page
in
range
(
1
,
3
):
for
page
in
range
(
1
,
3
):
data_json
=
getDataJson
(
page
)
data_json
=
getDataJson
(
page
)
...
@@ -138,13 +167,7 @@ def doJob():
...
@@ -138,13 +167,7 @@ def doJob():
data_
=
data_
.
replace
(
'
\\
'
,
''
)
data_
=
data_
.
replace
(
'
\\
'
,
''
)
soup
=
BeautifulSoup
(
data_
,
'lxml'
)
soup
=
BeautifulSoup
(
data_
,
'lxml'
)
data
=
getData
(
soup
,
num
)
data
=
getData
(
soup
,
num
)
data_list
.
append
(
data
)
log
.
info
(
f
'{data[1]}===采集成功'
)
num
+=
1
num
+=
1
time
.
sleep
(
3
)
df
=
pd
.
DataFrame
(
np
.
array
(
data_list
))
df
.
columns
=
[
'序号'
,
'标题'
,
'发布时间'
,
'来源'
,
'原文链接'
,
'发文时间'
,
'发文机构'
,
'发文字号'
,
'摘要'
,
'正文'
,
'附件名称'
,
'附件连接'
]
df
.
to_excel
(
'./相关政策/山东省人民政府/山东省人民政府政策文件.xlsx'
,
index
=
False
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论