新增获取账号地址的方法
This commit is contained in:
@@ -109,11 +109,52 @@ func (*TwitterService) Login(id int) *libs.ErrorInfo {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
getAccountInfo(page, int64(id))
|
||||
getRegisterInfo(page, int64(id), user.Password)
|
||||
// getAccountInfo(page, int64(id))
|
||||
// getRegisterInfo(page, int64(id), user.Password)
|
||||
return libs.ErrorCode["LoginSuccessful"]
|
||||
}
|
||||
|
||||
func (*TwitterService) GetAccountAddress(id int) *libs.ErrorInfo {
|
||||
UserService := InitTwitterAccountService()
|
||||
user := UserService.GetInfo(int64(id))
|
||||
obj := Browser.GetBrowser(id, &libs.Fingerprint{
|
||||
Proxy: user.Proxy,
|
||||
})
|
||||
// browser := obj.Browser
|
||||
page := obj.Page
|
||||
// 循环获取可用账号 到获取不到为止
|
||||
is := true
|
||||
for is {
|
||||
account := UserService.GetRandomAccount(&models.TwitterAccount{Type: "get_address", Status: "成功"})
|
||||
if account == nil {
|
||||
is = false
|
||||
}
|
||||
rod.Try(func() {
|
||||
// 进入账号信息页面
|
||||
page.MustNavigate("https://x.com/" + account.Name + "/about").MustWaitLoad()
|
||||
page.MustWaitNavigation()
|
||||
page.MustWaitLoad() // DOM 加载完成
|
||||
page.MustWaitIdle() // 基本静止(减少早期误判)
|
||||
page.MustActivate() // 前置
|
||||
// 获取地理位置
|
||||
locationElement, err := page.Timeout(10 * time.Second).Element(`#react-root > div > div > div.css-175oi2r.r-1f2l425.r-13qz1uu.r-417010.r-18u37iz > main > div > div > div > div.css-175oi2r.r-14lw9ot.r-jxzhtn.r-1ua6aaf.r-th6na.r-1phboty.r-16y2uox.r-184en5c.r-1abdc3e.r-1lg4w6u.r-f8sm7e.r-13qz1uu.r-1ye8kvj > div > div.css-175oi2r.r-16pcm1t > div.css-175oi2r.r-1wtj0ep.r-16x9es5.r-1mmae3n.r-1loqt21.r-o7ynqc.r-6416eg.r-1ny4l3l > div > div.css-175oi2r.r-16y2uox.r-1wbh5a2 > div:nth-child(2)`)
|
||||
if err == nil {
|
||||
location, _ := locationElement.Text()
|
||||
UserService.Update(account.ID, &models.TwitterAccount{
|
||||
Address: location,
|
||||
Status: "成功",
|
||||
})
|
||||
} else {
|
||||
UserService.Update(account.ID, &models.TwitterAccount{
|
||||
Status: "失败",
|
||||
})
|
||||
}
|
||||
time.Sleep(3 * time.Second)
|
||||
})
|
||||
}
|
||||
return libs.ErrorCode["GetAddressSuccessful"]
|
||||
}
|
||||
|
||||
// 获取账号信息
|
||||
func getAccountInfo(page *rod.Page, id int64) {
|
||||
profileButton := page.Timeout(10 * time.Second).MustElement(`a[data-testid="AppTabBar_Profile_Link"]`)
|
||||
|
||||
Reference in New Issue
Block a user