Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
丁双波
zzsn_spider
Commits
100460c6
提交
100460c6
authored
8月 17, 2024
作者:
XveLingKun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
天眼查-获取天眼查id
上级
8cf2bc43
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
203 行增加
和
0 行删除
+203
-0
getTycId.py
enterprise_tyc/getTycId.py
+203
-0
没有找到文件。
enterprise_tyc/getTycId.py
0 → 100644
浏览文件 @
100460c6
# 根据信用代码获取天眼查id
import
json
import
random
import
sys
import
time
import
pymysql
import
requests
from
retry
import
retry
from
base
import
BaseCore
import
urllib3
urllib3
.
disable_warnings
(
urllib3
.
exceptions
.
InsecureRequestWarning
)
requests
.
adapters
.
DEFAULT_RETRIES
=
5
baseCore
=
BaseCore
.
BaseCore
()
log
=
baseCore
.
getLogger
()
# headers = {
# 'Accept': 'application/json, text/plain, */*',
# 'Accept-Language': 'zh-CN,zh;q=0.9',
# 'Connection': 'keep-alive',
# 'Content-Length': '32',
# 'Content-Type': 'application/json',
# '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',
# 'version': 'TYC-Web'
# }
headers
=
{
'Accept-Language'
:
'zh-CN,zh;q=0.9'
,
'Content-Type'
:
'application/json'
,
'Connection'
:
'keep-alive'
,
'User-Agent'
:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
,
'version'
:
'TYC-Web'
}
header
=
{
'Accept'
:
'application/json, text/plain, */*'
,
'Accept-Encoding'
:
'gzip, deflate, br, zstd'
,
'Accept-Language'
:
'zh-CN,zh;q=0.9'
,
'Connection'
:
'keep-alive'
,
'Content-Length'
:
'93'
,
'Content-Type'
:
'application/json'
,
'Host'
:
'capi.tianyancha.com'
,
'Origin'
:
'https://www.tianyancha.com'
,
'Referer'
:
'https://www.tianyancha.com/'
,
'Sec-Fetch-Dest'
:
'empty'
,
'Sec-Fetch-Mode'
:
'cors'
,
'Sec-Fetch-Site'
:
'same-site'
,
'User-Agent'
:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
,
'X-AUTH-TOKEN'
:
'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzYzNjcxMTc0NiIsImlhdCI6MTcxNDk1Njg3MywiZXhwIjoxNzE3NTQ4ODczfQ.qMEvtETT7RS3Rhwq9idu5H2AKMxc2cjtr5bDDW6C6yOFKR-ErgDwT4SOBX9PB2LWDexAG2hNaeAvn6swr-n6VA'
,
'X-TYCID'
:
'dad485900fcc11ee8c0de34479b5b939'
,
'sec-ch-ua'
:
'"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"'
,
'sec-ch-ua-mobile'
:
'?0'
,
'sec-ch-ua-platform'
:
'"Windows"'
,
'version'
:
'TYC-Web'
}
# cnx = pymysql.connect(host='114.116.44.11', user='caiji', password='f7s0&7qqtK', db='dbScore', charset='utf8mb4')
# cursor= cnx.cursor()
cnx_
=
baseCore
.
cnx
cursor_
=
baseCore
.
cursor
taskType
=
'天眼查企业id/天眼查'
# 根据信用代码获取天眼查id 企业名字等信息
@retry
(
tries
=
5
,
delay
=
3
)
def
getTycIdByXYDM
(
com_name
,
s
):
retData
=
{
'state'
:
False
,
'tycData'
:
None
,
'reput'
:
True
}
url
=
f
"https://capi.tianyancha.com/cloud-tempest/search/suggest/v3?_={baseCore.getNowTime(3)}"
# url=f"https://capi.tianyancha.com/cloud-tempest/search/suggest/v3"
# ip = baseCore.get_proxy()
paramJsonData
=
{
'keyword'
:
com_name
}
# response = requests.post(url=url, json=paramJsonData, headers=header, verify=False, proxies=ip)
response
=
s
.
post
(
url
,
json
=
paramJsonData
,
headers
=
headers
)
time
.
sleep
(
random
.
randint
(
3
,
5
))
retJsonData
=
json
.
loads
(
response
.
content
.
decode
(
'utf-8'
))
if
retJsonData
[
'data'
]
and
retJsonData
[
'state'
]
==
'ok'
:
pass
else
:
log
.
error
(
f
"---{com_name}-未查询到该企业---"
)
retData
[
'reput'
]
=
False
return
retData
matchType
=
retJsonData
[
'data'
][
0
][
'matchType'
]
if
matchType
==
'信用代码匹配'
or
matchType
==
'公司名称匹配'
:
retData
[
'state'
]
=
True
retData
[
'tycData'
]
=
retJsonData
[
'data'
][
0
]
response
.
close
()
return
retData
else
:
log
.
error
(
f
"{com_name}------{retJsonData}"
)
response
.
close
()
return
retData
# 更新天眼查企业基本信息
def
updateTycInfo
():
while
True
:
# 根据从Redis中拿到的社会信用代码,在数据库中获取对应基本信息
social_code
=
baseCore
.
redicPullData
(
'NewsEnterprise:gnqy_socialCode'
)
# social_code = '9111000066990444XF'
# 判断 如果Redis中已经没有数据,则等待
if
social_code
==
None
:
time
.
sleep
(
20
)
continue
start
=
time
.
time
()
data
=
baseCore
.
getInfomation
(
social_code
)
if
len
(
data
)
!=
0
:
pass
else
:
# 数据重新塞入redis
baseCore
.
rePutIntoR
(
'NewsEnterprise:gnqy_socialCode'
,
social_code
)
continue
xydm
=
data
[
2
]
tycid
=
data
[
11
]
if
tycid
==
None
or
tycid
==
''
:
try
:
retData
=
getTycIdByXYDM
(
xydm
)
if
retData
[
'tycData'
]
and
retData
[
'reput'
]:
tycid
=
retData
[
'id'
]
# todo:写入数据库
updateSql
=
f
"update EnterpriseInfo set TYCID = '{tycid}' where SocialCode = '{xydm}'"
cursor_
.
execute
(
updateSql
)
cnx_
.
commit
()
elif
not
retData
[
'tycData'
]
and
retData
[
'reput'
]:
state
=
0
takeTime
=
baseCore
.
getTimeCost
(
start
,
time
.
time
())
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
takeTime
,
''
,
'获取天眼查id失败'
)
log
.
info
(
f
'======={social_code}====重新放入redis===='
)
baseCore
.
rePutIntoR
(
'NewsEnterprise:gnqy_socialCode'
,
social_code
)
continue
elif
not
retData
[
'reput'
]
and
not
retData
[
'tycData'
]:
continue
except
Exception
as
e
:
log
.
error
(
e
)
state
=
0
takeTime
=
baseCore
.
getTimeCost
(
start
,
time
.
time
())
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
takeTime
,
''
,
'获取天眼查id失败'
)
baseCore
.
rePutIntoR
(
'NewsEnterprise:gnqy_socialCode'
,
social_code
)
continue
# 从数据里获取天眼查id
def
getTycIdByDB
(
social_code
,
cursor
,
start
,
item
,
s
):
data
=
baseCore
.
getInfomation
(
social_code
)
if
len
(
data
)
!=
0
:
id
=
data
[
0
]
com_name
=
data
[
1
]
xydm
=
data
[
2
]
tycid
=
data
[
11
]
count
=
data
[
17
]
else
:
# 数据重新塞入redis
# log.info(f'数据库中无该企业{social_code}')
sql
=
f
"SELECT * FROM sys_base_enterprise WHERE social_credit_code = '{social_code}'"
cursor
.
execute
(
sql
)
data
=
cursor
.
fetchone
()
if
data
:
pass
else
:
# 数据库中并没有该企业 需要新增
pass
id
=
data
[
0
]
com_name
=
data
[
3
]
xydm
=
data
[
1
]
conut
=
0
# 写入数据库
insert
=
"INSERT INTO EnterpriseInfo(CompanyName, SocialCode) VALUES (
%
s,
%
s)"
cursor_
.
execute
(
insert
,
(
com_name
,
xydm
))
cnx_
.
commit
()
tycid
=
''
if
tycid
==
None
or
tycid
==
''
:
try
:
retData
=
getTycIdByXYDM
(
com_name
,
s
)
if
retData
[
'state'
]:
tycid
=
retData
[
'tycData'
][
'id'
]
# # todo:写入数据库
updateSql
=
f
"update EnterpriseInfo set TYCID = '{tycid}' where SocialCode = '{xydm}'"
cursor_
.
execute
(
updateSql
)
cnx_
.
commit
()
else
:
state
=
0
takeTime
=
baseCore
.
getTimeCost
(
start
,
time
.
time
())
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
takeTime
,
''
,
'获取天眼查id失败'
)
log
.
info
(
f
'======={social_code}====重新放入redis===='
)
baseCore
.
rePutIntoR
(
'CorPersonEnterpriseError:gnqy_socialCode'
,
item
)
return
None
except
:
state
=
0
takeTime
=
baseCore
.
getTimeCost
(
start
,
time
.
time
())
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
takeTime
,
''
,
'获取天眼查id失败'
)
baseCore
.
rePutIntoR
(
'CorPersonEnterpriseError:gnqy_socialCode'
,
item
)
return
None
return
tycid
if
__name__
==
'__main__'
:
updateTycInfo
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论