Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
6022510d
提交
6022510d
authored
8月 23, 2023
作者:
薛凌堃
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
工具包--数据库连接池
上级
27673f2e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
76 行增加
和
15 行删除
+76
-15
BaseCore.py
base/BaseCore.py
+76
-15
没有找到文件。
base/BaseCore.py
浏览文件 @
6022510d
...
...
@@ -15,6 +15,11 @@ from selenium.webdriver.chrome.service import Service
from
openpyxl
import
Workbook
import
langid
#创建连接池
import
pymysql
from
pymysql
import
connections
from
DBUtils.PooledDB
import
PooledDB
# 注意 程序退出前 调用BaseCore.close() 关闭相关资源
class
BaseCore
:
...
...
@@ -233,6 +238,20 @@ class BaseCore:
# 连接到Redis
self
.
r
=
redis
.
Redis
(
host
=
"114.115.236.206"
,
port
=
6379
,
password
=
'clbzzsn'
,
db
=
6
)
self
.
pool_caiji
=
PooledDB
(
creator
=
pymysql
,
maxconnections
=
5
,
mincached
=
2
,
maxcached
=
5
,
blocking
=
True
,
host
=
'114.115.159.144'
,
port
=
3306
,
user
=
'root'
,
password
=
'zzsn9988'
,
database
=
'caiji'
,
charset
=
'utf8mb4'
)
def
close
(
self
):
try
:
self
.
__cursor_proxy
.
close
()
...
...
@@ -432,34 +451,69 @@ class BaseCore:
# })
return
driver
# 根据社会信用代码获取企业信息
def
getInfomation
(
self
,
social_code
):
sql
=
f
"SELECT * FROM EnterpriseInfo WHERE SocialCode = '{social_code}'"
self
.
cursor
.
execute
(
sql
)
data
=
self
.
cursor
.
fetchone
()
data
=
[]
try
:
sql
=
f
"SELECT * FROM EnterpriseInfo WHERE SocialCode = '{social_code}'"
# self.cursor.execute(sql)
# data = self.cursor.fetchone()
conn
=
self
.
pool_caiji
.
connection
()
cursor
=
conn
.
cursor
()
cursor
.
execute
(
sql
)
data
=
cursor
.
fetchone
()
data
=
list
(
data
)
cursor
.
close
()
conn
.
close
()
except
:
log
=
self
.
getLogger
()
log
.
info
(
'=========数据库操作失败========'
)
return
data
# 更新企业采集次数
def
updateRun
(
self
,
social_code
,
runType
,
count
):
sql_update
=
f
"UPDATE EnterpriseInfo SET {runType} = {count} WHERE SocialCode = '{social_code}'"
self
.
cursor
.
execute
(
sql_update
)
self
.
cnx
.
commit
()
try
:
sql_update
=
f
"UPDATE EnterpriseInfo SET {runType} = {count} WHERE SocialCode = '{social_code}'"
# self.cursor.execute(sql_update)
# self.cnx.commit()
conn
=
self
.
pool_caiji
.
connection
()
cursor
=
conn
.
cursor
()
cursor
.
execute
(
sql_update
)
conn
.
commit
()
cursor
.
close
()
conn
.
close
()
except
:
log
=
self
.
getLogger
()
log
.
info
(
'======更新数据库失败======'
)
# 保存日志入库
def
recordLog
(
self
,
xydm
,
taskType
,
state
,
takeTime
,
url
,
e
):
createTime
=
self
.
getNowTime
(
1
)
ip
=
self
.
getIP
()
pid
=
self
.
getPID
()
sql
=
"INSERT INTO LogTable(SocialCode,TaskType,state,TakeTime,url,CreateTime,ProcessIp,PID,Exception) VALUES(
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s)"
values
=
[
xydm
,
taskType
,
state
,
takeTime
,
url
,
createTime
,
ip
,
pid
,
e
]
try
:
self
.
cursor
.
execute
(
sql
,
values
)
except
Exception
as
e
:
print
(
e
)
self
.
cnx
.
commit
()
createTime
=
self
.
getNowTime
(
1
)
ip
=
self
.
getIP
()
pid
=
self
.
getPID
()
sql
=
"INSERT INTO LogTable(SocialCode,TaskType,state,TakeTime,url,CreateTime,ProcessIp,PID,Exception) VALUES(
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s)"
values
=
[
xydm
,
taskType
,
state
,
takeTime
,
url
,
createTime
,
ip
,
pid
,
e
]
# try:
# self.cursor.execute(sql, values)
# except Exception as e:
# print(e)
# self.cnx.commit()
cnn
=
self
.
pool_caiji
.
connection
()
cursor
=
cnn
.
cursor
()
cursor
.
execute
(
sql
,
values
)
cnn
.
commit
()
cursor
.
close
()
cnn
.
close
()
except
:
log
=
self
.
getLogger
()
log
.
info
(
'======保存日志失败====='
)
#获取企查查token
def
GetToken
(
self
):
#获取企查查token
query
=
"select token from QCC_token "
# token = '67ec7402166df1da84ae83c4b95cefc0' # 需要隔两个小时左右抓包修改
...
...
@@ -518,3 +572,10 @@ class BaseCore:
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论