修改登录获取信息脚本
This commit is contained in:
@@ -110,6 +110,7 @@ func (*TwitterService) Login(id int) *libs.ErrorInfo {
|
||||
fmt.Println(err)
|
||||
}
|
||||
getAccountInfo(page, int64(id))
|
||||
getRegisterInfo(page, int64(id), user.Password)
|
||||
return libs.ErrorCode["LoginSuccessful"]
|
||||
}
|
||||
|
||||
@@ -170,6 +171,53 @@ func getAccountInfo(page *rod.Page, id int64) {
|
||||
})
|
||||
}
|
||||
|
||||
func getRegisterInfo(page *rod.Page, id int64, password string) {
|
||||
// 进入账号信息页面
|
||||
page.MustNavigate("https://x.com/settings/your_twitter_data/account").MustWaitLoad()
|
||||
page.MustWaitNavigation()
|
||||
page.MustWaitLoad() // DOM 加载完成
|
||||
page.MustWaitIdle() // 基本静止(减少早期误判)
|
||||
page.MustActivate() // 前置
|
||||
// 判断当前是否需要输入密码
|
||||
inpurPassword, err := page.Timeout(5 * time.Second).Element(`input[name="current_password"]`)
|
||||
if err == nil {
|
||||
if is, err1 := inpurPassword.Visible(); err1 == nil && is {
|
||||
inpurPassword.MustInput(password)
|
||||
}
|
||||
ConfirmButton := page.Timeout(5 * time.Second).MustElement(`button.css-175oi2r.r-sdzlij.r-1phboty.r-rs99b7.r-lrvibr.r-ddtstp.r-1xpp3t0.r-2yi16.r-1qi8awa.r-3pj75a.r-1loqt21.r-o7ynqc.r-6416eg.r-1ny4l3l`)
|
||||
ConfirmButton.MustClick()
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
// 获取创建时间
|
||||
dateElement := page.Timeout(10 * time.Second).MustElement(`#react-root > div > div > div.css-175oi2r.r-1f2l425.r-13qz1uu.r-417010.r-18u37iz > main > div > div > div > section:nth-child(2) > div.css-175oi2r.r-qocrb3.r-14lw9ot.r-1h0z5md.r-1jx8gzb.r-f8sm7e.r-13qz1uu.r-1ye8kvj > div > div:nth-child(6) > div:nth-child(2)`)
|
||||
createdAt, _ := dateElement.Text()
|
||||
// 获取注册IP
|
||||
ipElement := page.Timeout(10 * time.Second).MustElement(`#react-root > div > div > div.css-175oi2r.r-1f2l425.r-13qz1uu.r-417010.r-18u37iz > main > div > div > div > section:nth-child(2) > div.css-175oi2r.r-qocrb3.r-14lw9ot.r-1h0z5md.r-1jx8gzb.r-f8sm7e.r-13qz1uu.r-1ye8kvj > div > div:nth-child(6) > div:nth-child(3)`)
|
||||
ipAddr, _ := ipElement.Text()
|
||||
|
||||
// 分离IP地址和地区
|
||||
var ip, region string
|
||||
// ipAddr 格式: "68.132.165.85 (United States)"
|
||||
if strings.Contains(ipAddr, "(") {
|
||||
parts := strings.Split(ipAddr, " (")
|
||||
ip = strings.TrimSpace(parts[0])
|
||||
if len(parts) > 1 {
|
||||
region = strings.TrimRight(parts[1], ")")
|
||||
}
|
||||
} else {
|
||||
ip = ipAddr
|
||||
}
|
||||
log.Println("注册IP:", ip)
|
||||
log.Println("注册地区:", region)
|
||||
log.Println("创建时间:", createdAt)
|
||||
userService := InitTwitterAccountService()
|
||||
userService.Update(id, &models.TwitterAccount{
|
||||
RegisterIp: ip,
|
||||
RegisterDate: createdAt,
|
||||
RegisterAddress: region,
|
||||
})
|
||||
}
|
||||
|
||||
// 退出登录
|
||||
func (*TwitterService) Logout(id int) {
|
||||
Browser.CancelBrowser(id)
|
||||
@@ -705,7 +753,16 @@ func (*TwitterService) LoopViewPost(id int) *libs.ErrorInfo {
|
||||
time.Sleep(time.Duration(s2) * time.Second)
|
||||
log.Println("浏览推文内容链接:", v.ContentLink)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return libs.ErrorCode["ViewSuccessful"]
|
||||
}
|
||||
|
||||
// 导出 Twitter 账号数据到 Excel
|
||||
func (s *TwitterService) ExportAccounts() (code int, msg string, files []string) {
|
||||
result, err := ExportTwitterAccounts()
|
||||
if err != nil {
|
||||
return 500, "导出失败", nil
|
||||
}
|
||||
return 200, "导出成功", result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user