Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
480932b7
提交
480932b7
authored
11月 16, 2023
作者:
薛凌堃
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增企业自动化
上级
7d60109b
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
122 行增加
和
36 行删除
+122
-36
baseinfo1113.py
comData/BaseInfo_qcc/baseinfo1113.py
+0
-0
classtool.py
comData/BaseInfo_qcc/classtool.py
+112
-0
requestQCC.py
comData/BaseInfo_qcc/requestQCC.py
+10
-36
没有找到文件。
comData/BaseInfo_qcc/baseinfo1113.py
浏览文件 @
480932b7
差异被折叠。
点击展开。
comData/BaseInfo_qcc/classtool.py
0 → 100644
浏览文件 @
480932b7
import
os.path
from
openpyxl
import
Workbook
,
load_workbook
from
base.BaseCore
import
BaseCore
baseCore
=
BaseCore
()
log
=
baseCore
.
getLogger
()
cnx
=
baseCore
.
cnx
cursor
=
baseCore
.
cursor
class
File
():
# 创建文件
def
createFile
(
self
,
file_name
):
if
os
.
path
.
exists
(
file_name
):
return
else
:
wb
=
Workbook
()
sheet
=
wb
.
active
# 更改默认的sheet名称
sheet
.
title
=
"需处理企业"
sheet
.
append
([
"企业名称"
,
"社会信用代码"
])
# 创建另一个sheet
sheet2
=
wb
.
create_sheet
(
"获取基本信息成功企业"
)
sheet2
.
append
([
"企业名称"
,
"社会信用代码"
,
"采到的信用代码"
])
wb
.
save
(
file_name
)
wb
.
close
()
# 删除文件
def
deleteFile
(
self
,
file_name
):
if
os
.
path
.
exists
(
file_name
):
os
.
remove
(
file_name
)
else
:
pass
# 追加数据
def
appenddata
(
self
,
file_name
,
sheet
,
data
):
# 打开现有的Excel文件
wb
=
load_workbook
(
file_name
)
# 选择要追加数据的sheet
sheet
=
wb
[
sheet
]
sheet
.
append
(
data
)
# 保存Excel文件
wb
.
save
(
file_name
)
wb
.
close
()
class
Token
():
#获取token
def
getToken
(
self
):
cursor
.
execute
(
f
"select cookies from QCC_token order by update_time asc limit 1"
)
row
=
cursor
.
fetchall
()
cnx
.
commit
()
if
row
:
pass
else
:
#没有查到token
log
.
info
(
"没有拿到token"
)
return
False
return
row
[
0
]
# 删除失效的token
def
delete_token
(
self
,
cookie_
):
deletesql
=
f
"delete from QCC_token where cookies='{cookie_}' "
cursor
.
execute
(
deletesql
)
cnx
.
commit
()
class
Tag
():
# 删除特定属性标签
def
deletep
(
self
,
soup
,
tag_
,
attribute_to_delete
,
value_to_delete
):
if
attribute_to_delete
and
value_to_delete
:
# 查找带有指定属性的P标签并删除
tags
=
soup
.
find_all
(
tag_
,
{
attribute_to_delete
:
value_to_delete
})
for
tag
in
tags
:
# print(tag)
tag
.
decompose
()
else
:
tags
=
soup
.
find_all
(
tag_
)
for
tag
in
tags
:
# print(tag)
tag
.
decompose
()
# 删除空标签
def
deletek
(
self
,
soup
):
# 删除空白标签(例如<p></p>、<p><br></p>, img、video、hr除外)
for
i
in
soup
.
find_all
(
lambda
tag
:
len
(
tag
.
get_text
())
==
0
and
tag
.
name
not
in
[
"img"
,
"video"
,
"br"
]
and
tag
.
name
!=
"br"
or
tag
.
get_text
()
==
' '
or
tag
.
get_text
()
==
' '
):
for
j
in
i
.
descendants
:
if
j
.
name
in
[
"img"
,
"video"
,
"br"
]:
break
else
:
i
.
decompose
()
# 删除span标签
def
deletespan
(
self
,
td
):
spans
=
td
.
find_all
(
'span'
,
class_
=
'app-copy copy-button-item'
)
for
span
in
spans
:
if
'复制'
in
span
.
text
:
span
.
extract
()
# 删除span标签
spans2
=
td
.
find_all
(
'span'
,
slot
=
'content'
)
for
span2
in
spans2
:
if
'趋势图'
in
span2
.
text
:
span2
.
extract
()
spans3
=
td
.
find_all
(
'span'
,
class_
=
'm-l-r-10'
)
for
span3
in
spans3
:
if
'年报'
in
span3
.
text
:
span3
.
extract
()
spans4
=
td
.
find_all
(
'span'
,
class_
=
'text-span'
)
for
span4
in
spans4
:
span4
.
extract
()
\ No newline at end of file
comData/BaseInfo_qcc/requestQCC.py
浏览文件 @
480932b7
"""模拟扫码登录"""
import
json
import
time
import
requests
...
...
@@ -11,6 +12,7 @@ from selenium.webdriver.support.ui import WebDriverWait
from
selenium.webdriver.support
import
expected_conditions
as
EC
from
base.BaseCore
import
BaseCore
from
pymysql.converters
import
escape_string
baseCore
=
BaseCore
()
log
=
baseCore
.
getLogger
()
cnx_
=
baseCore
.
cnx
...
...
@@ -34,41 +36,7 @@ def flushAndGetToken():
for
cookie
in
cookie_list
:
cookies
[
cookie
[
'name'
]]
=
cookie
[
'value'
]
print
(
cookies
)
insert
=
f
"insert into QCC_token (token,cookies,create_time,fenghao_time,user_name,update_time) values ('{token}','{escape_string(cookies)}',now(),DATE_SUB(NOW(), INTERVAL 1 DAY),'{user_name}',now())"
cursor_
.
execute
(
insert
)
cnx_
.
commit
()
baseCore
.
close
()
def
getrequest_soup
(
headers
,
url
):
req
=
requests
.
get
(
headers
=
headers
,
url
=
url
)
result
=
BeautifulSoup
(
req
.
content
,
'html.parser'
)
return
result
def
dojob
():
headers
=
{
'Accept'
:
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'
,
'Accept-Encoding'
:
'gzip, deflate, br'
,
'Accept-Language'
:
'zh-CN,zh;q=0.9'
,
'Connection'
:
'keep-alive'
,
'Cookie'
:
'qcc_did=046d99c9-566e-4046-9094-689901b79748; UM_distinctid=18aac5b8c21810-046f8431aecf58-26031f51-1fa400-18aac5b8c22efd; CNZZDATA1254842228=109635008-1695108795-https
%253
A
%252
F
%252
Fwww.qcc.com
%252
F
%7
C1695113473; _uab_collina=169935323766710839405007; QCCSESSID=1d489139eea4830a062c3a1240; acw_tc=db9062ad16994955552435350e3b43e7e5cee64c77d9f807936897ab1f'
,
'Host'
:
'www.qcc.com'
,
'Referer'
:
'https://www.qcc.com/'
,
'Sec-Ch-Ua'
:
'"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"'
,
'Sec-Ch-Ua-Mobile'
:
'?0'
,
'Sec-Ch-Ua-Platform'
:
'"Windows"'
,
'Sec-Fetch-Dest'
:
'document'
,
'Sec-Fetch-Mode'
:
'navigate'
,
'Sec-Fetch-Site'
:
'same-origin'
,
'Sec-Fetch-User'
:
'?1'
,
'Upgrade-Insecure-Requests'
:
'1'
,
'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'
}
url
=
'https://www.qcc.com/api/userCenter/getAuthInfo'
soup
=
getrequest_soup
(
headers
,
url
)
pass
return
cookies
if
__name__
==
"__main__"
:
urlqcc
=
'https://www.qcc.com/'
...
...
@@ -81,7 +49,13 @@ if __name__ == "__main__":
# print(soup)
browser
.
find_element
(
By
.
CLASS_NAME
,
'nav-item'
)
.
click
()
time
.
sleep
(
20
)
flushAndGetToken
()
cookies
=
flushAndGetToken
()
cookies
=
json
.
dumps
(
cookies
)
insert
=
f
"insert into QCC_token (cookies,create_time,fenghao_time,update_time) values ('{escape_string(cookies)}',now(),DATE_SUB(NOW(), INTERVAL 1 DAY),now())"
cursor_
.
execute
(
insert
)
cnx_
.
commit
()
baseCore
.
close
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论