修改登录获取信息脚本
This commit is contained in:
83
services/twitter_account_export_service.go
Normal file
83
services/twitter_account_export_service.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"go-account-register/models"
|
||||
"log"
|
||||
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
// 导出 Twitter 账号数据到 Excel
|
||||
func ExportTwitterAccounts() ([]string, error) {
|
||||
accountService := InitTwitterAccountService()
|
||||
accounts := accountService.GetAll(&models.TwitterAccount{
|
||||
Type: "get",
|
||||
})
|
||||
|
||||
// 分类
|
||||
countryMap := map[string][]models.TwitterAccount{
|
||||
"United States": {},
|
||||
"Singapore": {},
|
||||
"Japan": {},
|
||||
"Taiwan": {},
|
||||
"Other": {},
|
||||
}
|
||||
for _, acc := range accounts {
|
||||
addr := acc.RegisterAddress
|
||||
if addr == "United States" || addr == "Singapore" || addr == "Japan" || addr == "Taiwan" {
|
||||
countryMap[addr] = append(countryMap[addr], acc)
|
||||
} else {
|
||||
countryMap["Other"] = append(countryMap["Other"], acc)
|
||||
}
|
||||
}
|
||||
|
||||
var files []string
|
||||
for k, v := range countryMap {
|
||||
if len(v) == 0 {
|
||||
continue
|
||||
}
|
||||
file := excelize.NewFile()
|
||||
titles := []string{"编号", "用户id", "用户名", "邮箱", "密码", "邮箱密码", "生日", "Token", "二步验证码", "Cookies", "类型", "状态", "登录状态", "代理", "浏览器ID", "浏览器地址", "注册时间", "注册地区", "注册IP", "更新时间", "创建时间"}
|
||||
for i, t := range titles {
|
||||
cell, _ := excelize.CoordinatesToCellName(i+1, 1)
|
||||
file.SetCellValue("Sheet1", cell, t)
|
||||
}
|
||||
for row, acc := range v {
|
||||
vals := []interface{}{
|
||||
acc.ID,
|
||||
acc.Uid,
|
||||
acc.Name,
|
||||
acc.Email,
|
||||
acc.Password,
|
||||
acc.EmailPassword,
|
||||
acc.Birthday,
|
||||
acc.Token,
|
||||
acc.Fa2,
|
||||
acc.Cookies,
|
||||
acc.Type,
|
||||
acc.Status,
|
||||
acc.LoginStatus,
|
||||
acc.Proxy,
|
||||
acc.BrowserId,
|
||||
acc.BrowserUrl,
|
||||
acc.RegisterDate,
|
||||
acc.RegisterAddress,
|
||||
acc.RegisterIp,
|
||||
acc.UpdateTime,
|
||||
acc.CreateTime,
|
||||
}
|
||||
for col, val := range vals {
|
||||
cell, _ := excelize.CoordinatesToCellName(col+1, row+2)
|
||||
file.SetCellValue("Sheet1", cell, val)
|
||||
}
|
||||
}
|
||||
filename := "twitter_accounts_" + k + ".xlsx"
|
||||
if err := file.SaveAs(filename); err != nil {
|
||||
log.Println("保存文件失败:", filename, err)
|
||||
} else {
|
||||
files = append(files, filename)
|
||||
log.Println("已导出:", filename)
|
||||
}
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
@@ -17,6 +17,12 @@ func InitTwitterAccountService() *TwitterAccountService {
|
||||
return &TwitterAccountService{db: db}
|
||||
}
|
||||
|
||||
func (t *TwitterAccountService) GetAll(params *models.TwitterAccount) []models.TwitterAccount {
|
||||
var accounts []models.TwitterAccount
|
||||
t.db.Model(&models.TwitterAccount{}).Where(params).Find(&accounts)
|
||||
return accounts
|
||||
}
|
||||
|
||||
func (t *TwitterAccountService) Create(params *models.TwitterAccount) int64 {
|
||||
params.CreateTime = time.Now().Unix()
|
||||
params.UpdateTime = time.Now().Unix()
|
||||
|
||||
@@ -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