Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
丁双波
zzsn_spider
Commits
6da55a3e
提交
6da55a3e
authored
4月 30, 2024
作者:
XveLingKun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
微信公众号详情采集调整
上级
c12087c7
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
39 行增加
和
17 行删除
+39
-17
oneWeixin2.py
comData/weixin_solo/oneWeixin2.py
+39
-17
没有找到文件。
comData/weixin_solo/oneWeixin2.py
浏览文件 @
6da55a3e
# -*- coding: utf-8 -*-
'''
成功100 发送数据失败200 请求失败400 文章内容为空500
成功100 发送数据失败200 请求失败400 文章内容为空500
处理style标签失败700
'''
import
re
...
...
@@ -65,7 +65,7 @@ def getjsonInfo():
cnx_
.
commit
()
return
dict_json
,
linkid
@retry
(
tries
=
3
,
delay
=
2
)
@retry
(
tries
=
20
,
delay
=
2
)
def
getrequest
(
url_news
):
ip
=
baseCore
.
get_proxy
()
...
...
@@ -74,7 +74,7 @@ def getrequest(url_news):
raise
return
res_news
def
get_info
(
dict_json
):
def
get_info
(
dict_json
,
linkid
):
# list_all_info = []
# num_caiji = 0
kaishi_time
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
())
...
...
@@ -91,11 +91,14 @@ def get_info(dict_json):
url_news
=
dict_json
[
'link'
]
info_source_code
=
dict_json
[
'info_source_code'
]
# while True:
# try:
# ip = baseCore.get_proxy()
# res_news = requests.get(url_news, proxies=ip, timeout=20)
# break
# except:
# #400请求失败
# time.sleep(3)
#400请求失败
# updatewxLink(url_news, info_source_code, 400)
# return False
...
...
@@ -104,11 +107,15 @@ def get_info(dict_json):
res_news
=
getrequest
(
url_news
)
# print(res_news)
except
:
try
:
res_news
=
requests
.
get
(
url_news
,
timeout
=
20
)
except
:
# 400请求失败
updatewxLink
(
url_news
,
info_source_code
,
400
)
# 修改回原状态,重新放入redis
updatewxLink
(
url_news
,
info_source_code
,
0
)
log
.
info
(
f
'{origin}---{news_date}--{news_title}---请求失败-- 重新放入redis'
)
baseCore
.
rePutIntoR
(
'WeiXinGZH:linkid'
,
linkid
)
# try:
# res_news = requests.get(url_news, timeout=20)
# except:
# # 400请求失败
# updatewxLink(url_news, info_source_code, 400)
return
False
soup_news
=
BeautifulSoup
(
res_news
.
content
,
'html.parser'
)
try
:
...
...
@@ -120,7 +127,11 @@ def get_info(dict_json):
del
news_html
[
'id'
]
del
news_html
[
'class'
]
except
Exception
as
e
:
log
.
error
(
f
'{url_news}-----{info_source_code}'
)
log
.
info
(
f
'--errorCode:700--{url_news}-----------{e}'
)
# log.error(f'{url_news}-----{info_source_code}')
updatewxLink
(
url_news
,
info_source_code
,
0
)
log
.
info
(
f
'{origin}---{news_date}--{news_title}---style标签解析失败---重新放入redis'
)
baseCore
.
rePutIntoR
(
'WeiXinGZH:linkid'
,
linkid
)
return
False
try
:
news_content
=
news_html
.
text
...
...
@@ -137,7 +148,7 @@ def get_info(dict_json):
insertSql
=
f
"insert into WeixinGZH (site_name,site_url,json_error_info,error_type,create_time) values (
%
s,
%
s,
%
s,
%
s,
%
s)"
cursor_
.
execute
(
insertSql
,
tuple
(
false
))
cnx_
.
commit
()
updatewxLink
(
url_news
,
info_source_code
,
500
)
updatewxLink
(
url_news
,
info_source_code
,
500
)
return
False
list_img
=
news_html
.
find_all
(
'img'
)
...
...
@@ -161,22 +172,33 @@ def get_info(dict_json):
except
:
img_one
.
extract
()
continue
resp
=
None
for
i
in
range
(
10
):
try
:
resp
=
obsClient
.
putContent
(
'zzsn'
,
name_img
,
content
=
res
.
content
)
break
except
:
time
.
sleep
(
2
)
if
resp
:
pass
else
:
img_one
.
extract
()
continue
try
:
url_img
=
resp
[
'body'
][
'objectUrl'
]
str_url_img
=
f
'<img src="{url_img}">'
except
Exception
as
e
:
log
.
info
(
f
'--error--{url_news}-----------{e}'
)
log
.
info
(
f
'--error
Code:300
--{url_news}-----------{e}'
)
updatewxLink
(
url_news
,
info_source_code
,
300
)
return
False
try
:
img_one
.
replace_with
(
BeautifulSoup
(
str_url_img
,
'lxml'
)
.
img
)
except
Exception
as
e
:
log
.
info
(
f
'--error--{url_news}-----------{e}'
)
log
.
info
(
f
'--error
Code:300
--{url_news}-----------{e}'
)
updatewxLink
(
url_news
,
info_source_code
,
300
)
return
False
except
Exception
as
e
:
log
.
info
(
f
'--error--{url_news}-----------{e}'
)
log
.
info
(
f
'--error
Code:600
--{url_news}-----------{e}'
)
updatewxLink
(
url_news
,
info_source_code
,
600
)
return
False
...
...
@@ -214,7 +236,7 @@ def get_info(dict_json):
except
:
time
.
sleep
(
5
)
log
.
info
(
'------数据发送kafka失败------'
)
updatewxLink
(
url_news
,
info_source_code
,
200
)
updatewxLink
(
url_news
,
info_source_code
,
200
)
continue
list_all_info
.
append
(
dic_info
)
...
...
@@ -237,7 +259,7 @@ def get_info(dict_json):
except
:
time
.
sleep
(
5
)
continue
updatewxLink
(
url_news
,
info_source_code
,
100
)
updatewxLink
(
url_news
,
info_source_code
,
100
)
return
True
def
rm_style_attr
(
soup
):
...
...
@@ -277,7 +299,7 @@ if __name__=="__main__":
dict_json
,
linkid
=
getjsonInfo
()
try
:
if
dict_json
:
if
get_info
(
dict_json
):
if
get_info
(
dict_json
,
linkid
):
num_caiji
=
num_caiji
+
1
log
.
info
(
f
'-----已采集{num_caiji}篇文章---来源{dict_json["site_name"]}----'
)
else
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论