Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
3fdea62f
提交
3fdea62f
authored
11月 30, 2023
作者:
薛凌堃
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
北京市人民政府
上级
401719e1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
66 行增加
和
37 行删除
+66
-37
policy-beijing.py
REITs专题数据/policy-beijing.py
+66
-37
没有找到文件。
REITs专题数据/policy-beijing.py
浏览文件 @
3fdea62f
impor
t
os
impor
t
os
import
os
import
os
import
random
import
random
import
re
import
fitz
import
numpy
as
np
import
openpyxl
import
pandas
as
pd
import
requests
import
requests
from
bs4
import
BeautifulSoup
from
bs4
import
BeautifulSoup
from
datetime
import
datetime
import
time
import
time
from
openpyxl
import
load_workbook
from
retry
import
retry
from
retry
import
retry
from
selenium
import
webdriver
from
selenium.webdriver.chrome.service
import
Service
from
urllib.parse
import
urljoin
from
urllib.parse
import
urljoin
import
BaseCore
import
BaseCore
...
@@ -23,8 +11,14 @@ import BaseCore
...
@@ -23,8 +11,14 @@ import BaseCore
baseCore
=
BaseCore
.
BaseCore
()
baseCore
=
BaseCore
.
BaseCore
()
log
=
baseCore
.
getLogger
()
log
=
baseCore
.
getLogger
()
from
reits
import
Policy
policy
=
Policy
()
topic
=
'policy'
webname
=
'北京市人民政府'
class
Policy
():
class
Policy
1
():
@retry
(
tries
=
3
,
delay
=
10
)
@retry
(
tries
=
3
,
delay
=
10
)
def
getrequest_soup
(
self
,
url
):
def
getrequest_soup
(
self
,
url
):
ip
=
baseCore
.
get_proxy
()
ip
=
baseCore
.
get_proxy
()
...
@@ -137,7 +131,7 @@ def getFjContent(url):
...
@@ -137,7 +131,7 @@ def getFjContent(url):
def
beijing
():
def
beijing
():
if
not
os
.
path
.
exists
(
'./相关政策/北京市人民政府/政策文件'
):
if
not
os
.
path
.
exists
(
'./相关政策/北京市人民政府/政策文件'
):
os
.
makedirs
(
'./相关政策/北京市人民政府/政策文件'
)
os
.
makedirs
(
'./相关政策/北京市人民政府/政策文件'
)
policy
=
Policy
()
policy
1
=
Policy1
()
url
=
'https://www.beijing.gov.cn/so/ss/query/s'
url
=
'https://www.beijing.gov.cn/so/ss/query/s'
payload
=
{
payload
=
{
'siteCode'
:
'1100000088'
,
'siteCode'
:
'1100000088'
,
...
@@ -191,24 +185,31 @@ def beijing():
...
@@ -191,24 +185,31 @@ def beijing():
data
=
policy
.
requestPost
(
headers
,
url
,
payload_page
)
data
=
policy
.
requestPost
(
headers
,
url
,
payload_page
)
info_list
=
data
[
'resultDocs'
]
info_list
=
data
[
'resultDocs'
]
for
info_
in
info_list
:
for
info_
in
info_list
:
fjtitle_list
=
''
id_list
=
[]
fjhref_list
=
''
info
=
info_
[
'data'
]
info
=
info_
[
'data'
]
origin
=
info
[
'siteLabel'
][
'value'
]
.
lstrip
()
.
strip
()
origin
=
info
[
'siteLabel'
][
'value'
]
.
lstrip
()
.
strip
()
title
=
info
[
'titleO'
]
.
lstrip
()
.
strip
()
title
=
info
[
'titleO'
]
.
lstrip
()
.
strip
()
titleLabel
=
info
[
'titleLabel'
][
'value'
]
.
lstrip
()
.
strip
()
titleLabel
=
info
[
'titleLabel'
][
'value'
]
.
lstrip
()
.
strip
()
publishDate
=
info
[
'docDate'
]
.
lstrip
()
.
strip
()
publishDate
=
info
[
'docDate'
]
.
lstrip
()
.
strip
()
newsUrl
=
info
[
'url'
]
.
lstrip
()
.
strip
()
newsUrl
=
info
[
'url'
]
.
lstrip
()
.
strip
()
# 根据链接判重
is_member
=
baseCore
.
r
.
sismember
(
'REITs::'
+
webname
,
newsUrl
)
if
is_member
:
continue
summary
=
info
[
'summary'
]
.
lstrip
()
.
strip
()
summary
=
info
[
'summary'
]
.
lstrip
()
.
strip
()
summary
=
BeautifulSoup
(
summary
,
'lxml'
)
.
text
.
lstrip
()
.
strip
()
summary
=
BeautifulSoup
(
summary
,
'lxml'
)
.
text
.
lstrip
()
.
strip
()
writtenDate
=
''
writtenDate
=
None
pub_hao
=
''
pub_hao
=
''
organ
=
''
organ
=
''
content
=
''
topicClassification
=
''
if
titleLabel
==
'政策解读'
:
if
titleLabel
==
'政策解读'
:
try
:
try
:
newssoup
=
policy
.
getrequest_soup
(
newsUrl
)
newssoup
=
policy
1
.
getrequest_soup
(
newsUrl
)
except
:
except
:
newssoup
=
policy
.
getrequest_soup_
(
newsUrl
)
newssoup
=
policy
1
.
getrequest_soup_
(
newsUrl
)
contentWithTag
=
newssoup
.
find
(
'div'
,
id
=
'mainText'
)
contentWithTag
=
newssoup
.
find
(
'div'
,
id
=
'mainText'
)
try
:
try
:
scripts
=
contentWithTag
.
find_all
(
'script'
)
scripts
=
contentWithTag
.
find_all
(
'script'
)
...
@@ -223,13 +224,14 @@ def beijing():
...
@@ -223,13 +224,14 @@ def beijing():
except
:
except
:
pass
pass
content
=
contentWithTag
.
text
.
lstrip
()
.
strip
()
content
=
contentWithTag
.
text
.
lstrip
()
.
strip
()
contentWithTag_str
=
str
(
contentWithTag
)
organ
=
newssoup
.
find
(
'div'
,
class_
=
'othermessage'
)
.
find
(
'p'
,
class_
=
'fl'
)
.
text
.
split
(
'来源:'
)[
organ
=
newssoup
.
find
(
'div'
,
class_
=
'othermessage'
)
.
find
(
'p'
,
class_
=
'fl'
)
.
text
.
split
(
'来源:'
)[
1
]
.
lstrip
()
.
strip
()
1
]
.
lstrip
()
.
strip
()
elif
titleLabel
==
'政策文件'
:
elif
titleLabel
==
'政策文件'
:
try
:
try
:
newssoup
=
policy
.
getrequest_soup
(
newsUrl
)
newssoup
=
policy
1
.
getrequest_soup
(
newsUrl
)
except
:
except
:
newssoup
=
policy
.
getrequest_soup_
(
newsUrl
)
newssoup
=
policy
1
.
getrequest_soup_
(
newsUrl
)
contentWithTag
=
newssoup
.
find
(
'div'
,
id
=
'mainText'
)
contentWithTag
=
newssoup
.
find
(
'div'
,
id
=
'mainText'
)
try
:
try
:
scripts
=
contentWithTag
.
find_all
(
'script'
)
scripts
=
contentWithTag
.
find_all
(
'script'
)
...
@@ -248,39 +250,66 @@ def beijing():
...
@@ -248,39 +250,66 @@ def beijing():
if
'成文日期'
in
li
.
text
:
if
'成文日期'
in
li
.
text
:
writtenDate
=
li
.
find
(
'span'
)
.
text
.
lstrip
()
.
strip
()
writtenDate
=
li
.
find
(
'span'
)
.
text
.
lstrip
()
.
strip
()
content
=
contentWithTag
.
text
.
lstrip
()
.
strip
()
content
=
contentWithTag
.
text
.
lstrip
()
.
strip
()
contentWithTag_str
=
str
(
contentWithTag
)
formatRows
=
info
[
'formatRows'
]
formatRows
=
info
[
'formatRows'
]
for
row
in
formatRows
:
for
row
in
formatRows
:
for
col
in
row
[
'col'
]:
for
col
in
row
[
'col'
]:
name
=
col
[
'text'
]
name
=
col
[
'text'
]
if
name
==
'相关附件'
:
if
name
==
'相关附件'
:
tag_str
=
''
value
=
col
[
'value'
]
value
=
col
[
'value'
]
for
i
in
range
(
len
(
value
.
keys
())):
for
i
in
range
(
len
(
value
.
keys
())):
file_href
=
list
(
value
.
keys
())[
i
]
file_href
=
list
(
value
.
keys
())[
i
]
file_name
=
list
(
value
.
values
())[
i
]
file_name
=
list
(
value
.
values
())[
i
]
fjcontent
=
getFjContent
(
file_href
)
category
=
os
.
path
.
splitext
(
file_href
)[
1
]
category
=
os
.
path
.
splitext
(
file_href
)[
1
]
if
category
not
in
file_name
:
if
category
not
in
file_name
:
file_name
=
file_name
+
category
file_name
=
file_name
+
category
file_name
=
f
'{num}-{publishDate}-{file_name}'
file
=
f
'./相关政策/北京市人民政府/政策文件/{file_name}'
# 上传附件至obs
fjtitle_list
+=
file_name
+
'
\n
'
att_id
,
full_path
=
policy
.
attuributefile
(
file_name
,
file_href
,
num
,
publishDate
)
with
open
(
file
,
'wb'
)
as
f
:
if
att_id
:
f
.
write
(
fjcontent
)
id_list
.
append
(
att_id
)
log
.
info
(
f
'{file_name}===附件下载成功'
)
tag
=
newssoup
.
find
(
'ul'
,
class_
=
'fujian'
)
.
find_all
(
'a'
)[
i
]
tag
[
'href'
]
=
full_path
tag_str
+=
str
(
tag
)
+
'<br>'
contentWithTag_str
+=
tag_str
elif
'号'
in
name
:
elif
'号'
in
name
:
pub_hao
=
col
[
'value'
]
.
lstrip
()
.
strip
()
pub_hao
=
col
[
'value'
]
.
lstrip
()
.
strip
()
elif
'发文机构'
in
name
:
elif
'发文机构'
in
name
:
organ
=
col
[
'value'
][
0
]
.
lstrip
()
.
strip
()
organ
=
col
[
'value'
][
0
]
.
lstrip
()
.
strip
()
elif
'主题分类'
in
name
:
topicClassification
=
col
[
'value'
][
0
]
.
lstrip
()
.
strip
()
time_now
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
())
if
content
==
''
:
continue
dic_info
=
{
'attachmentIds'
:
id_list
,
'author'
:
''
,
'content'
:
content
,
'contentWithTag'
:
contentWithTag_str
,
'deleteFlag'
:
0
,
'id'
:
''
,
'title'
:
title
,
'publishDate'
:
publishDate
,
'origin'
:
origin
,
'sourceAddress'
:
newsUrl
,
'writtenDate'
:
writtenDate
,
'organ'
:
organ
,
'topicClassification'
:
topicClassification
,
'issuedNumber'
:
pub_hao
,
'summary'
:
summary
,
'createDate'
:
time_now
,
'sid'
:
'1729041207245328385'
,
}
try
:
baseCore
.
sendkafka
(
dic_info
,
topic
)
baseCore
.
r
.
sadd
(
'REITs::'
+
webname
,
newsUrl
)
log
.
info
(
f
'采集成功--{title}--{newsUrl}'
)
except
:
for
att_id
in
id_list
:
baseCore
.
deliteATT
(
att_id
)
time
.
sleep
(
random
.
randint
(
10
,
20
))
time
.
sleep
(
random
.
randint
(
10
,
20
))
data
=
[
num
,
title
,
publishDate
,
origin
,
newsUrl
,
writtenDate
,
organ
,
pub_hao
,
summary
,
content
,
fjtitle_list
,
fjhref_list
]
data_list
.
append
(
data
)
log
.
info
(
f
'{title}===采集成功'
)
num
+=
1
num
+=
1
df
=
pd
.
DataFrame
(
np
.
array
(
data_list
))
df
.
columns
=
[
'序号'
,
'标题'
,
'发布时间'
,
'来源'
,
'原文链接'
,
'发文时间'
,
'发文机构'
,
'发文字号'
,
'摘要'
,
'正文'
,
'附件名称'
,
'附件连接'
]
df
.
to_excel
(
'./相关政策/北京市人民政府/北京市人民政府政策文件.xlsx'
,
index
=
False
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
beijing
()
beijing
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论