Skip to content

Instantly share code, notes, and snippets.

@dongfg
Created November 7, 2019 06:56
Show Gist options
  • Save dongfg/8b320a2921674eb2da6cc26a093c64c8 to your computer and use it in GitHub Desktop.
Save dongfg/8b320a2921674eb2da6cc26a093c64c8 to your computer and use it in GitHub Desktop.
淘宝自动删除订单
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
"strings"
"time"
)
func main() {
WAIT:
wait := 10
for !check() {
fmt.Println("Target window not found, waiting ... ", wait)
wait--
time.Sleep(time.Second * 1)
if wait == 0 {
break
}
}
count := 0
for {
if !check() {
goto WAIT
}
rand := 1
if count%2 == 0 {
rand = -1
}
// move to delete button
robotgo.MoveMouseSmooth(1184+rand, 481+rand)
robotgo.MouseClick("left", true)
// move to confirm button
robotgo.MoveMouseSmooth(687+rand, 345+rand)
color := robotgo.GetPixelColor(687+rand, 345+rand)
// 1f8cd8 and 449fde
if !(color == "1f8cd8" || color == "449fde") {
robotgo.KeyTap("r", "lcmd")
time.Sleep(time.Second * 1)
robotgo.MoveMouseSmooth(910, 212)
robotgo.MouseClick("left", true)
time.Sleep(time.Second * 2)
}
robotgo.MouseClick("left", false)
count++
if count > 1000 {
break
}
}
}
func check() bool {
// 已买到的宝贝 - Google Chrome
title := robotgo.GetTitle()
if !strings.HasPrefix(title, "已买到的宝贝") {
return false
}
return true
}
在已买到宝贝页面操作,https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm
golang 版本,利用 github.com/go-vgo/robotgo 移动鼠标,点击删除按钮实现。
需要的坐标数据使用 GetMousePos 获取(简单方法,sleep 2s,切换到已买到宝贝页面窗口)
基本思路:
1.检测当前时候处于“已买到宝贝”页面(获取浏览器窗口标题,测试基于 Chrome),可在运行过程中切换窗口实现停止操作
2.点击删除按钮
3.点击确认删除按钮(连续多次点击同一坐标会触发风控(滑动滑块后才能继续操作),此处简单加减1防止被风控,测试有效,上同)
4.多次删除后会出现订单列表为空的情况,此处简单根据确认按钮处坐标颜色判断是不是这种情况
5.如果出现了4,刷新当前页面(在 mac 上测试,因此使用 cmd + r 刷新),移动鼠标点击确定刷新按钮,goto 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment