Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
98200599
提交
98200599
authored
12月 04, 2023
作者:
薛凌堃
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
辽宁省人民政府
上级
362b085c
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
47 行增加
和
14 行删除
+47
-14
policy-liaoning.py
REITs专题数据/policy-liaoning.py
+47
-14
没有找到文件。
REITs专题数据/policy-liaoning.py
浏览文件 @
98200599
impor
t
time
impor
t
time
...
...
@@ -6,11 +6,17 @@ import pandas as pd
import
requests
from
bs4
import
BeautifulSoup
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'
}
...
...
@@ -22,13 +28,14 @@ def getContent(url):
soup
=
BeautifulSoup
(
req
.
text
,
'html.parser'
)
contentWithTag
=
soup
.
find
(
'div'
,
class_
=
'zfwj_detail'
)
pub_hao
=
contentWithTag
.
find
(
'p'
,
class_
=
'wjh'
)
.
text
.
lstrip
()
.
strip
()
content
=
contentWithTag
.
text
.
lstrip
()
.
strip
()
return
content
,
pub_hao
return
content
WithTag
,
pub_hao
def
doJob
():
url
=
'https://www.ln.gov.cn/search/pcRender?pageId=7b2aa485f97e40e4a0b4b635f36eda6c'
driver
=
baseCore
.
buildDriver
()
# driver = baseCore.buildDriver()
driver
=
policy
.
createDriver
()
driver
.
get
(
url
)
time
.
sleep
(
1
)
driver
.
find_element
(
By
.
CLASS_NAME
,
'conFl_con'
)
.
find_elements
(
By
.
TAG_NAME
,
'a'
)[
-
1
]
.
find_element
(
By
.
TAG_NAME
,
...
...
@@ -39,24 +46,50 @@ def doJob():
time
.
sleep
(
1
)
div_list
=
driver
.
find_elements
(
By
.
CLASS_NAME
,
'searchMod'
)
num
=
1
data_list
=
[]
for
div
in
div_list
:
title
=
div
.
find_element
(
By
.
TAG_NAME
,
'a'
)
.
text
.
replace
(
'
\n
'
,
''
)
.
lstrip
()
.
strip
()
href
=
div
.
find_element
(
By
.
TAG_NAME
,
'a'
)
.
get_attribute
(
'href'
)
# 根据链接判重
is_member
=
baseCore
.
r
.
sismember
(
'REITs::'
+
webname
,
href
)
if
is_member
:
continue
summary
=
div
.
find_element
(
By
.
CLASS_NAME
,
'txtCon'
)
.
find_element
(
By
.
TAG_NAME
,
'a'
)
.
text
.
replace
(
'
\n
'
,
''
)
.
lstrip
()
.
strip
()
publishDate
=
div
.
find_element
(
By
.
CLASS_NAME
,
'dates'
)
.
text
.
split
(
'时间:'
)[
1
]
.
replace
(
'年'
,
'-'
)
.
replace
(
'月'
,
'-'
)
.
replace
(
'日'
,
''
)
.
lstrip
()
.
strip
()
content
,
pub_hao
=
getContent
(
href
)
data
=
[
num
,
title
,
publishDate
,
'辽宁省人民政府'
,
href
,
''
,
''
,
pub_hao
,
summary
,
content
,
''
,
''
]
data_list
.
append
(
data
)
log
.
info
(
f
'{title}===采集成功'
)
contentWithTag
,
pub_hao
=
getContent
(
href
)
content
=
contentWithTag
.
text
.
lstrip
()
.
strip
()
contentWithTag_str
=
str
(
contentWithTag
)
time_now
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
())
dic_info
=
{
'attachmentIds'
:
[],
'author'
:
''
,
'content'
:
content
,
'contentWithTag'
:
contentWithTag_str
,
'deleteFlag'
:
0
,
'id'
:
''
,
'title'
:
title
,
'publishDate'
:
publishDate
,
'origin'
:
'辽宁省人民政府'
,
'sourceAddress'
:
url
,
'writtenDate'
:
''
,
'organ'
:
''
,
'topicClassification'
:
''
,
'issuedNumber'
:
pub_hao
,
'summary'
:
summary
,
'createDate'
:
time_now
,
'sid'
:
'1729042213737967618'
,
}
try
:
baseCore
.
sendkafka
(
dic_info
,
topic
)
baseCore
.
r
.
sadd
(
'REITs::'
+
webname
,
url
)
log
.
info
(
f
'采集成功--{title}--{url}'
)
except
Exception
as
e
:
continue
num
+=
1
driver
.
close
()
df
=
pd
.
DataFrame
(
np
.
array
(
data_list
))
df
.
columns
=
[
'序号'
,
'标题'
,
'发布时间'
,
'来源'
,
'原文链接'
,
'发文时间'
,
'发文机构'
,
'发文字号'
,
'摘要'
,
'正文'
,
'附件名称'
,
'附件连接'
]
df
.
to_excel
(
'./辽宁省人民政府政策文件.xlsx'
,
index
=
False
)
if
__name__
==
'__main__'
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论