Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
0b43a864
提交
0b43a864
authored
8月 31, 2024
作者:
XveLingKun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
中央全面深化改革会议
上级
fb623647
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
35 行增加
和
7 行删除
+35
-7
zyqmshggldxzhy19.py
comData/important_meeting/zyqmshggldxzhy19.py
+35
-7
没有找到文件。
comData/important_meeting/zyqmshggldxzhy19.py
浏览文件 @
0b43a864
...
...
@@ -10,7 +10,7 @@ from datetime import datetime
from
kafka
import
KafkaProducer
sys
.
path
.
append
(
'D:
\\
kkwork
\\
zzsn_spider
\
\
base'
)
sys
.
path
.
append
(
r'D:\PycharmProjects\zzsn
\base'
)
import
BaseCore
baseCore
=
BaseCore
.
BaseCore
()
log
=
baseCore
.
getLogger
()
...
...
@@ -51,6 +51,26 @@ headers = {
}
if
__name__
==
"__main__"
:
from
selenium
import
webdriver
headers
=
{
'user-agent'
:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36'
,
}
opt
=
webdriver
.
ChromeOptions
()
opt
.
add_argument
(
'user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
)
opt
.
add_argument
(
"--ignore-certificate-errors"
)
opt
.
add_argument
(
"--ignore-ssl-errors"
)
opt
.
add_experimental_option
(
"excludeSwitches"
,
[
"enable-automation"
])
opt
.
add_experimental_option
(
'excludeSwitches'
,
[
'enable-logging'
])
opt
.
add_experimental_option
(
'useAutomationExtension'
,
False
)
# opt.binary_location = r'F:\spider\Google\Chrome\Application\chrome.exe'
# chromedriver = r'F:\spider\cmd100\chromedriver.exe'
opt
.
binary_location
=
r'D:\Google\Chrome\Application\chrome.exe'
chromedriver
=
r'D:\cmd100\chromedriver.exe'
browser
=
webdriver
.
Chrome
(
chrome_options
=
opt
,
executable_path
=
chromedriver
)
# 中央全面深化改革委员会会议
r
=
redis
.
Redis
(
host
=
'114.116.90.53'
,
port
=
6380
,
password
=
'clbzzsn'
,
db
=
5
)
# 中央全面深化改革领导小组会议
...
...
@@ -86,14 +106,21 @@ if __name__ == "__main__":
summary
=
ul
.
find
(
'a'
)
.
text
# todo: 链接判重
try
:
flag
=
r
.
sismember
(
info_code
,
newsUrl
)
if
flag
:
flag
_
=
r
.
sismember
(
info_code
,
newsUrl
)
if
flag
_
:
log
.
info
(
'信息已采集入库过'
)
continue
except
Exception
as
e
:
continue
news_request
=
requests
.
get
(
url
=
newsUrl
,
headers
=
headers
,
allow_redirects
=
False
)
news_soup
=
BeautifulSoup
(
news_request
.
content
,
'html.parser'
)
if
news_request
==
200
:
news_soup
=
BeautifulSoup
(
news_request
.
content
,
'html.parser'
)
else
:
browser
.
get
(
newsUrl
)
page_source
=
browser
.
page_source
# print(page_source)
news_soup
=
BeautifulSoup
(
page_source
,
'html.parser'
)
# print(news_soup)
try
:
title
=
news_soup
.
find
(
'h1'
,
class_
=
'big_title'
)
.
text
...
...
@@ -128,10 +155,10 @@ if __name__ == "__main__":
kafka_result
=
producer
.
send
(
"research_center_fourth"
,
json
.
dumps
(
dic_info
,
ensure_ascii
=
False
)
.
encode
(
'utf8'
))
# r.sadd(info_code + '-test', sourceAddress)
print
(
'发送kafka结束'
)
log
.
info
(
'发送kafka结束'
)
except
Exception
as
e
:
print
(
e
)
print
(
'发送kafka异常!'
)
log
.
info
(
e
)
log
.
info
(
'发送kafka异常!'
)
finally
:
producer
.
close
()
flag
+=
1
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论