Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
doudian-py
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
baiquan
doudian-py
Commits
1a85ce89
Commit
1a85ce89
authored
Jul 01, 2025
by
baiquan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
获取token
parent
4ea0e1b3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
3 deletions
+35
-3
service/page_login.py
+28
-1
shop.py
+1
-2
utils/errors.py
+6
-0
No files found.
service/page_login.py
View file @
1a85ce89
import
re
import
time
from
DrissionPage.errors
import
*
from
datetime
import
datetime
,
timedelta
from
DrissionPage
import
Chromium
from
DrissionPage._functions.by
import
By
from
DrissionPage.errors
import
*
from
loguru
import
logger
from
dao.db
import
find_account_by_environment_id
...
...
@@ -99,8 +102,32 @@ async def page_login(browser_id):
logger
.
error
(
f
"{browser_id}-->{e}"
)
except
Exception
as
e
:
logger
.
error
(
f
"{browser_id}-->{e}"
)
for
_
in
range
(
3
):
if
tab
.
title
==
"首页"
:
set_token
(
tab
)
tab
.
close
()
return
tab
.
wait
(
3
)
raise
AppError
(
"登录失败-->未获取到token"
)
def
set_token
(
tab
):
token_pattern
=
r'"token":\s*"([a-f0-9]{32})"'
token_match
=
re
.
search
(
token_pattern
,
tab
.
html
)
if
token_match
:
token
=
token_match
.
group
(
1
)
# 设置 30 天后过期
expires
=
(
datetime
.
now
()
+
timedelta
(
days
=
30
))
.
strftime
(
"
%
a,
%
d
%
b
%
Y
%
H:
%
M:
%
S GMT"
)
cookies
=
(
f
'_shop_token_={token}; '
'path=/; '
'domain=.fxg.jinritemai.com; '
f
'expires={expires}; '
# 指定过期时间
'Secure; '
# 仅 HTTPS 传输
'HttpOnly'
# 禁止 JS 访问
)
tab
.
set
.
cookies
(
cookies
)
else
:
raise
AppError
(
"未找到 token"
)
def
listen_login
(
tab
):
for
packet
in
tab
.
listen
.
steps
(
timeout
=
10
):
...
...
shop.py
View file @
1a85ce89
...
...
@@ -181,8 +181,7 @@ async def run():
}
try
:
tasks
=
await
get_task
(
upload_data
)
# tasks = {"data": [{"app_name": "admin", "type": 1, "browser_type": 1}]}
# tasks = {"data": [{"app_name": "admin", "type": 1, "browser_type": 1, "browser_id": "1075653218"},
# tasks = {"data": [{"app_name": "admin", "type": 1, "browser_type": 1, "browser_id": "1075653218"},]}
# {"app_name": "admin", "type": 1, "browser_type": 1, "browser_id": "1075653218"},
# {"app_name": "admin", "type": 1, "browser_type": 1, "browser_id": "1075653218"},
# {"app_name": "admin", "type": 1, "browser_type": 1, "browser_id": "1075653218"},
...
...
utils/errors.py
View file @
1a85ce89
...
...
@@ -24,3 +24,8 @@ class ABogusParamsError(AppError):
"""a_bogus参数异常"""
def
__init__
(
self
,
msg
=
'a_bogus参数错误'
,
data
=
None
):
super
()
.
__init__
(
code
=
401
,
msg
=
msg
,
data
=
data
)
class
CookiesExpiredError
(
AppError
):
"""cookies过期异常"""
def
__init__
(
self
,
msg
=
'cookies过期'
,
data
=
None
):
super
()
.
__init__
(
code
=
402
,
msg
=
msg
,
data
=
data
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment