Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spider
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
selection-new
spider
Commits
d51420d8
Commit
d51420d8
authored
Apr 08, 2026
by
Peng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
3650247a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
39 deletions
+43
-39
alipay_account_order.py
py_spider/amazon_spider/alipay_account_order.py
+43
-39
No files found.
py_spider/amazon_spider/alipay_account_order.py
View file @
d51420d8
...
...
@@ -19,6 +19,7 @@ class get_1688_order_data():
self
.
alipay_data_list
=
[]
self
.
err_orders_list
=
[]
# 有问题的订单号
self
.
time_num
=
0
self
.
chrom_new_page_tab
=
None
# 浏览器标签页,初始化为 None
def
redis_db
(
self
):
nums
=
0
...
...
@@ -40,8 +41,13 @@ class get_1688_order_data():
chrome_options
.
set_local_port
(
9333
)
# 设置 Chrome 的调试端口
chrom_page
=
ChromiumPage
(
addr_or_opts
=
chrome_options
)
print
(
f
"Chrome 浏览器运行在端口: {9333}"
)
try
:
self
.
get_order_tab
(
chrom_page
,
list_orders
,
orders_type
)
# 请求订单页面。判断是否保持登录状态
chrom_page
.
quit
()
finally
:
try
:
chrom_page
.
quit
()
# 无论是否报错,都确保退出浏览器
except
:
pass
def
get_order_tab
(
self
,
chrom_page
,
list_orders
,
orders_type
):
url
=
'https://air.1688.com/app/ctf-page/trade-order-list/buyer-order-list.html?tradeStatus=waitbuyerpay&spm=a260k.home2025.topmenu.dmyorder_popup_ddaifukuan&page=1&pageSize=10'
...
...
@@ -183,14 +189,18 @@ class get_1688_order_data():
}
}
if
orders_type
:
for
retry
in
range
(
3
):
try
:
json_data
=
json
.
dumps
(
items
,
ensure_ascii
=
False
)
self
.
redis_db22
.
rpush
(
'alipay_zszh:response'
,
json_data
)
print
(
f
'从alipay_zszh:{self.account} redis删除订单号:'
,
order_num
)
self
.
redis_db22
.
lrem
(
f
'alipay_zszh:{self.account}'
,
1
,
order_num
)
break
except
Exception
as
e
:
print
(
f
'redis写入失败,第{retry+1}次重试: {e}'
)
self
.
redis_db22
=
self
.
redis_db
()
time
.
sleep
(
2
)
continue
except
:
pass
else
:
self
.
alipay_data_list
.
append
(
items
)
else
:
...
...
@@ -233,8 +243,8 @@ class get_1688_order_data():
print
(
'寻找支付方式'
)
# 对公支付
chrom_page_tab
.
scroll
.
down
(
180
)
time
.
sleep
(
random
.
randint
(
1
,
2
))
channel_name
=
chrom_page_tab
.
ele
(
'xpath://span[contains(text(),"对公支付")]'
,
timeout
=
5
)
time
.
sleep
(
random
.
randint
(
2
,
4
))
channel_name
=
chrom_page_tab
.
ele
(
'xpath://span[contains(text(),"对公支付")]'
,
timeout
=
8
)
if
channel_name
:
print
(
'对公支付'
)
chrom_page_tab
.
ele
(
'xpath://span[contains(text(),"对公支付")]'
,
timeout
=
3
)
.
click
()
...
...
@@ -265,16 +275,21 @@ class get_1688_order_data():
_items
=
None
if
_items
:
if
orders_type
:
for
retry
in
range
(
3
):
try
:
json_data
=
json
.
dumps
(
_items
,
ensure_ascii
=
False
)
self
.
redis_db22
.
rpush
(
'alipay_zszh:response'
,
json_data
)
print
(
f
'从alipay_zszh:{self.account} redis删除订单号:'
,
order_num
)
self
.
redis_db22
.
lrem
(
f
'alipay_zszh:{self.account}'
,
1
,
order_num
)
except
:
pass
break
except
Exception
as
e
:
print
(
f
'redis写入失败,第{retry+1}次重试: {e}'
)
self
.
redis_db22
=
self
.
redis_db
()
time
.
sleep
(
2
)
else
:
self
.
alipay_data_list
.
append
(
_items
)
self
.
save_redis
()
chrom_page_tab
.
close
()
# 关闭标签页,防止资源泄漏
continue
if
orders_type
is
None
:
print
(
', 点击网银'
)
...
...
@@ -311,6 +326,7 @@ class get_1688_order_data():
chrom_page_tab
.
ele
(
'xpath://div[contains(text(),"专属账号余额:")]'
,
timeout
=
3
)
.
click
()
except
:
pass
try
:
time
.
sleep
(
random
.
randint
(
1
,
3
))
if
chrom_page_tab
.
ele
(
'xpath://div[contains(text(),"专属账号余额不足")]'
):
resp
=
chrom_page_tab
.
html
...
...
@@ -367,50 +383,27 @@ class get_1688_order_data():
except
:
print
(
'删除失败:'
)
pass
chrom_page_tab
.
close
()
# 关闭标签页
except
Exception
as
e
:
print
(
f
'专属账号支付 redis 操作失败: {e}'
)
if
'connection'
in
str
(
e
)
.
lower
()
or
'timeout'
in
str
(
e
)
.
lower
():
print
(
'Redis 连接失败,重新初始化...'
)
self
.
redis_db22
=
self
.
redis_db
()
finally
:
chrom_page_tab
.
close
()
# 无论如何都关闭标签页
continue
else
:
zfb
=
chrom_page_tab
.
ele
(
'xpath://span[contains(text(),"支付宝")]'
,
timeout
=
3
)
.
click
()
if
zfb
:
print
(
'找到支付宝。开始选择支付宝'
)
if
self
.
click_pay
(
chrom_page_tab
,
order_num
):
items_err
=
{
"account"
:
self
.
account
,
"order_id"
:
order_num
,
"type"
:
"异常"
,
"json"
:
{
"value"
:
'系统繁忙,请重试
'
"value"
:
'没有对公支付
'
}
}
self
.
alipay_data_list
.
append
(
items_err
)
else
:
self
.
online_zfb
(
chrom_page_tab
,
order_num
)
else
:
print
(
'没有找到可以支付方式。退出 订单号。'
,
order_num
)
items
=
{
"account"
:
self
.
account
,
"order_id"
:
order_num
,
"type"
:
"无"
,
"json"
:
{
"value"
:
None
}
}
self
.
alipay_data_list
.
append
(
items
)
chrom_page_tab
.
close
()
# 关闭标签页
self
.
save_redis
()
# def save_alipay_zszh(self,_items, order_num):
# self.redis_db()
# for i in range(5):
# try:
# json_data = json.dumps(_items, ensure_ascii=False)
# self.redis_db22.rpush('alipay_zszh:response', json_data)
# print(f'从alipay_zszh:{self.account} redis删除订单号:', order_num)
# self.redis_db22.lrem(f'alipay_zszh:{self.account}', 1, order_num)
# break
# except:
# time.sleep(10)
def
save_redis
(
self
):
if
self
.
alipay_data_list
:
for
alipay_data
in
self
.
alipay_data_list
:
...
...
@@ -422,8 +415,8 @@ class get_1688_order_data():
break
except
:
print
(
'写入redis报错:重试'
)
self
.
redis_db22
=
self
.
redis_db
()
# 重连 redis
time
.
sleep
(
5
)
# 删除
try
:
print
(
'从redis删除订单号:'
,
alipay_data
[
'order_id'
])
self
.
redis_db22
.
lrem
(
f
"alipay:{self.account}"
,
1
,
f
"{alipay_data['order_id']}"
)
...
...
@@ -560,8 +553,19 @@ class get_1688_order_data():
self
.
get_alipay_zszh
()
except
Exception
as
e
:
print
(
"报错xx2222xxx:"
,
e
,
f
"
\n
{traceback.format_exc()}"
)
# 检测到 redis 连接失败,重新初始化
if
'redis'
in
str
(
e
)
.
lower
()
or
'connection'
in
str
(
e
)
.
lower
()
or
'timeout'
in
str
(
e
)
.
lower
():
print
(
'Redis 连接失败,重新初始化...'
)
self
.
redis_db22
=
self
.
redis_db
()
time
.
sleep
(
300
)
# 安全关闭浏览器标签页
if
hasattr
(
self
,
'chrom_new_page_tab'
)
and
self
.
chrom_new_page_tab
:
try
:
self
.
chrom_new_page_tab
.
close
()
except
:
pass
self
.
err_orders_list
=
[]
# 异常时也清空,防止累积
continue
# 继续下一轮循环,不退出
base_min
,
base_max
=
20
,
60
sleep_min
=
base_min
+
self
.
time_num
*
2
...
...
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