Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
丁双波
zzsn_spider
Commits
a492eb60
提交
a492eb60
authored
9月 05, 2023
作者:
薛凌堃
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
微信公众号获取正文
上级
a9ad4913
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
28 行增加
和
63 行删除
+28
-63
oneWeixin2.py
comData/weixin_solo/oneWeixin2.py
+28
-63
没有找到文件。
comData/weixin_solo/oneWeixin2.py
浏览文件 @
a492eb60
...
@@ -4,18 +4,14 @@
...
@@ -4,18 +4,14 @@
'''
'''
import
requests
,
time
,
random
,
json
,
pymysql
,
redis
import
requests
,
time
,
random
,
json
,
pymysql
,
redis
import
pandas
as
pd
import
urllib3
import
urllib3
from
bs4
import
BeautifulSoup
from
bs4
import
BeautifulSoup
from
openpyxl
import
Workbook
from
selenium
import
webdriver
from
obs
import
ObsClient
from
obs
import
ObsClient
from
kafka
import
KafkaProducer
from
kafka
import
KafkaProducer
# logging.basicConfig(filename='example.log', level=logging.INFO)
from
base.BaseCore
import
BaseCore
from
base.BaseCore
import
BaseCore
import
os
baseCore
=
BaseCore
()
baseCore
=
BaseCore
()
log
=
baseCore
.
getLogger
()
log
=
baseCore
.
getLogger
()
cnx_
=
baseCore
.
cnx
cnx_
=
baseCore
.
cnx
...
@@ -25,48 +21,6 @@ cursor_ = baseCore.cursor
...
@@ -25,48 +21,6 @@ cursor_ = baseCore.cursor
r
=
baseCore
.
r
r
=
baseCore
.
r
urllib3
.
disable_warnings
()
urllib3
.
disable_warnings
()
def
check_url
(
sid
,
article_url
):
r
=
redis
.
Redis
(
host
=
"114.115.236.206"
,
port
=
6379
,
password
=
'clbzzsn'
)
res
=
r
.
sismember
(
f
'wx_url_{sid}'
,
article_url
)
if
res
==
1
:
return
True
else
:
return
False
def
add_url
(
sid
,
article_url
):
r
=
redis
.
Redis
(
host
=
"114.115.236.206"
,
port
=
6379
,
password
=
'clbzzsn'
)
res
=
r
.
sadd
(
f
'wx_url_{sid}'
,
article_url
,
3
)
# 注意是 保存set的方式
if
res
==
0
:
# 若返回0,说明插入不成功,表示有重复
return
True
else
:
return
False
# #定时
# def getFromSql():
# selectSql = "SELECT info_source_code from info_source where site_uri like '%mp.weixin.qq.com%'"
# cursor.execute(selectSql)
# results = cursor.fetchall()
# result_list = [item[0] for item in results]
#
# #放入redis
# for item in result_list:
# r.rpush('WeiXinGZH:infoSourceCode', item)
#
# #刷新浏览器并获得token
# def flushAndGetToken(list_b):
# browser_run = list_b[0]
# log.info('======刷新浏览器=====')
# browser_run.refresh()
# cookie_list = browser_run.get_cookies()
# cur_url = browser_run.current_url
# token = cur_url.split('token=')[1]
# log.info(f'===========当前token为:{token}============')
# cookies = {}
# for cookie in cookie_list:
# cookies[cookie['name']] = cookie['value']
# return token,cookies
#采集失败的公众号 重新放入redis
def
rePutIntoR
(
item
):
def
rePutIntoR
(
item
):
r
.
rpush
(
'WeiXinGZH:infoSourceCode'
,
item
)
r
.
rpush
(
'WeiXinGZH:infoSourceCode'
,
item
)
...
@@ -165,22 +119,33 @@ def get_info(dict_json):
...
@@ -165,22 +119,33 @@ def get_info(dict_json):
img_one
.
extract
()
img_one
.
extract
()
else
:
else
:
try
:
try
:
name_img
=
url_src
.
split
(
'/'
)[
-
2
]
+
'.'
+
url_src
.
split
(
'wx_fmt='
)[
1
]
try
:
except
:
name_img
=
url_src
.
split
(
'/'
)[
-
2
]
+
'.'
+
url_src
.
split
(
'wx_fmt='
)[
1
]
img_one
.
extract
()
except
:
continue
img_one
.
extract
()
try
:
continue
res
=
requests
.
get
(
url_src
,
timeout
=
20
)
try
:
except
:
res
=
requests
.
get
(
url_src
,
timeout
=
20
)
img_one
.
extract
()
except
:
resp
=
obsClient
.
putContent
(
'zzsn'
,
name_img
,
content
=
res
.
content
)
img_one
.
extract
()
continue
url_img
=
resp
[
'body'
][
'objectUrl'
]
resp
=
obsClient
.
putContent
(
'zzsn'
,
name_img
,
content
=
res
.
content
)
str_url_img
=
f
'<img src="{url_img}">'
try
:
try
:
url_img
=
resp
[
'body'
][
'objectUrl'
]
img_one
.
replace_with
(
BeautifulSoup
(
str_url_img
,
'lxml'
)
.
img
)
str_url_img
=
f
'<img src="{url_img}">'
except
Exception
as
e
:
log
.
info
(
f
'--error--{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}'
)
updatewxLink
(
url_news
,
info_source_code
,
300
)
return
False
except
Exception
as
e
:
except
Exception
as
e
:
log
.
info
(
f
'----{url_news}-----------{e}'
)
log
.
info
(
f
'--error--{url_news}-----------{e}'
)
updatewxLink
(
url_news
,
info_source_code
,
600
)
return
False
return
False
for
tag
in
news_html
.
descendants
:
for
tag
in
news_html
.
descendants
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论