谷狗 邮箱注册selenium自动化运营脚本,配合chromedriver使用

不废话,直接上代码

# 防封策略:
#       1.模拟人工输入字符串和输入字符间隔时间
#       2.每注册一个账号就修改浏览器指纹
#       3.每注册一个账号就切换ip代理
#       4.注册ip的地址必须与手机号同一国家

import csv
import random
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
import getverifysms
import string
import ip_get_foreigh
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.action_chains import ActionChains


# 注册新账号
class Google_signup:

    def getip(self):
        ip_list = ip_get_foreigh.getip()
        ip_addr = random.choice(ip_list)[0]
        print(ip_list, '\n', ip_addr)
        return ip_addr

    def sign_up_now(self):

        UA_LIST = ['Mozilla/5.0 (compatible; U; ABrowse 0.6; Syllable) AppleWebKit/420+ (KHTML, like Gecko)',
                   'Mozilla/5.0 (compatible; U; ABrowse 0.6;  Syllable) AppleWebKit/420+ (KHTML, like Gecko)',
                   'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Acoo Browser 1.98.744; .NET CLR '
                   '3.5.30729)',
                   'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Acoo Browser 1.98.744; .NET CLR   '
                   '3.5.30729)',
                   'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0;   Acoo Browser; GTB5; Mozilla/4.0 '
                   '(compatible; MSIE 6.0; Windows NT 5.1;   SV1) ; InfoPath.1; .NET CLR 3.5.30729; .NET CLR '
                   '3.0.30618)',
                   'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; Acoo Browser; .NET CLR '
                   '2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; Avant Browser)',
                   'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1;   .NET CLR 2.0.50727; '
                   'Media Center PC 5.0; .NET CLR 3.0.04506)',
                   'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; GTB5; Mozilla/4.0 (compatible; '
                   'MSIE 6.0; Windows NT 5.1; SV1) ; Maxthon; InfoPath.1; .NET CLR 3.5.30729; .NET CLR 3.0.30618)',
                   'Mozilla/4.0 (compatible; Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Acoo '
                   'Browser 1.98.744; .NET CLR 3.5.30729); Windows NT 5.1; Trident/4.0)',
                   'Mozilla/4.0 (compatible; Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6; '
                   'Acoo Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727); Windows NT 5.1; Trident/4.0; Maxthon; .NET '
                   'CLR 2.0.50727; .NET CLR 1.1.4322; InfoPath.2)',
                   'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Acoo Browser; GTB6; Mozilla/4.0 ('
                   'compatible; MSIE 6.0; Windows NT 5.1; SV1) ; InfoPath.1; .NET CLR 3.5.30729; .NET CLR 3.0.30618)']
        option = webdriver.ChromeOptions()
        # 用Chrome地址栏输入chrome://version/,查看自己的“个人资料路径”,然后在浏览器启动时,调用这个配置文件
        # option.add_argument(r'--user-data-dir=C:\Users\Administrator\AppData\Local\Google\Chrome\User Data')
        # option.add_argument('--proxy-server=%s' % self.getip())
        option.add_argument('--user-agent=%s' % random.choice(UA_LIST))
        self.driver = webdriver.Chrome(options=option)
        mouse_action = ActionChains(self.driver)

        try:
            # 清除缓存提示框
            self.driver.get('chrome://settings/clearBrowserData')
            # 2S 等待时间
            time.sleep(2)
            clearButton = self.driver.execute_script(
                "return document.querySelector('settings-ui').shadowRoot.querySelector("
                "'settings-main').shadowRoot.querySelector('settings-basic-page').shadowRoot.querySelector("
                "'settings-section > settings-privacy-page').shadowRoot.querySelector("
                "'settings-clear-browsing-data-dialog').shadowRoot.querySelector("
                "'#clearBrowsingDataDialog').querySelector('#clearBrowsingDataConfirm')")
            clearButton.click()

            # 请求注册页面
            time.sleep(5)
            self.driver.get('https://accounts.google.com/signup/v2/webcreateaccount?flowName=GlifWebSignIn&flowEntry'
                            '=SignUp')
            time.sleep(random.randint(5, 10))

            psw_value = ''      # 邮箱密码,建议统一,也可以自己设置一个邮箱密码列表,随机选取,更安全

            while True:
                # 姓氏名字,密码确认填入,下一步
                # 填入姓,自己设置
                lastname_list = ['li', 'zhao', 'smith', 'gogo', 'wang', 'zhang', 'zhao', 'qian' 'Jones', 'Williams', 'Brown', 'Davies', 'Evans',
                     'White', 'Walker']
                lastname_str = random.choice(lastname_list)
                self.driver.find_element_by_xpath('//input[@id="lastName"]').click()
                self.driver.find_element_by_xpath('//input[@id="lastName"]').clear()
                for lastname_str_each in lastname_str:
                    self.driver.find_element_by_xpath('//input[@id="lastName"]').send_keys(lastname_str_each)   # 填入姓
                    time.sleep(random.random())    # 暂停0-1秒之间随机时间
                time.sleep(random.randint(5, 10))

                # 填入名,自己设置
                firstName_list = ['wei', 'fang', 'min', 'jing', 'bin', 'yun', 'li', 'ying', 'Judy', 'Jessica', 'Ashley', 'Emily',
                     'Sarah', 'Samantha', 'Amanda', 'Brittany']
                firstName_str = random.choice(firstName_list)
                self.driver.find_element_by_xpath('//input[@id="firstName"]').click()
                self.driver.find_element_by_xpath('//input[@id="firstName"]').clear()
                for firstName_str_each in firstName_str:
                    self.driver.find_element_by_xpath('//input[@id="firstName"]').send_keys(firstName_str_each)  # 填入名
                    time.sleep(random.random())  # 暂停0-1秒之间随机时间
                time.sleep(random.randint(5, 10))

                # 填入邮箱
                usrname_str = lastname_str + firstName_str + ''.join(random.sample(string.digits, random.randint(2, 5)))
                self.driver.find_element_by_xpath('//input[@name="Username"]').click()
                self.driver.find_element_by_xpath('//input[@name="Username"]').send_keys(Keys.CONTROL + 'a')
                # self.driver.find_element_by_xpath('//input[@name="Username"]').clear()
                time.sleep(random.random())  # 暂停0-1秒之间随机时间
                for usrname_str_each in usrname_str:
                    self.driver.find_element_by_xpath('//input[@name="Username"]').send_keys(usrname_str_each)       # 填入邮箱账号
                    time.sleep(random.random())  # 暂停0-1秒之间随机时间
                time.sleep(random.randint(5, 10))

                # 填入密码
                self.driver.find_element_by_xpath('//input[@name="Passwd"]').click()
                self.driver.find_element_by_xpath('//input[@name="Passwd"]').clear()
                for psw_value_each in psw_value:
                    self.driver.find_element_by_xpath('//input[@name="Passwd"]').send_keys(psw_value_each)       # 填入密码
                    time.sleep(random.random())  # 暂停0-1秒之间随机时间
                time.sleep(random.randint(5, 10))

                # 确认密码
                self.driver.find_element_by_xpath('//input[@name="ConfirmPasswd"]').click()
                self.driver.find_element_by_xpath('//input[@name="ConfirmPasswd"]').clear()
                for psw_value_each in psw_value:
                    self.driver.find_element_by_xpath('//input[@name="ConfirmPasswd"]').send_keys(psw_value_each)    # 确认密码
                    time.sleep(random.random())  # 暂停0-1秒之间随机时间
                time.sleep(random.randint(5, 10))

                lastname_input_value = self.driver.find_element_by_xpath('//input[@id="lastName"]').get_attribute('value')
                firstname_input_value = self.driver.find_element_by_xpath('//input[@id="firstName"]').get_attribute('value')
                usrname_str_true = self.driver.find_element_by_xpath('//input[@name="Username"]').get_attribute('value')
                psw_str_value = self.driver.find_element_by_xpath('//input[@name="Passwd"]').get_attribute('value')
                pswcp_str_value = self.driver.find_element_by_xpath('//input[@name="ConfirmPasswd"]').get_attribute('value')

                if (lastname_input_value != '') and (firstname_input_value != '') and (usrname_str_true != '') and (psw_str_value != '') and (pswcp_str_value != ''):
                    break
                else:
                    self.driver.refresh()  # 刷新方法 refresh
                    time.sleep(10)
                    pass

            # 模拟鼠标点击下一步
            next_step1 = self.driver.find_element_by_xpath('//*[@id="accountDetailsNext"]')  # 下一步
            mouse_action.click(next_step1)
            mouse_action.perform()
            time.sleep(random.randint(5, 10))

            # 购买手机号,并检测手机号是否可用
            while True:
                # 购买手机号
                data = getverifysms.buyphone('google')
                order_id = data[0]
                phone_number = data[1]
                time.sleep(random.randint(5, 10))
                for phone_number_each in phone_number:
                    self.driver.find_element_by_xpath('//input[@type="tel"]').send_keys(phone_number_each)  # 填入手机号
                    time.sleep(random.random())  # 暂停0-1秒之间随机时间
                time.sleep(random.randint(2, 5))

                # 模拟鼠标点击下一步
                next_step2 = self.driver.find_element_by_xpath('//*[@class="FliLIb DL0QTb"]')  # 点击下一步
                mouse_action.click(next_step2)
                mouse_action.perform()
                time.sleep(random.randint(5, 10))

                # 对'该号码无法用于进行验证'异常处理
                # try:
                # 检测'该号码无法用于进行验证'
                cant_number = self.driver.find_elements_by_css_selector('[class="o6cuMc"]')  # 该号码无法用于进行验证
                if len(cant_number) > 0:
                    getverifysms.cancel(str(order_id))  # 取消前面的订单
                    time.sleep(random.randint(5, 10))
                    self.driver.find_element_by_xpath('//input[@type="tel"]').clear()  # 清空号码输入框内容
                    print('该号码无法用于进行验证,取消订单重新购买')
                    pass
                else:  # 如果该号码可以用于验证
                    # break
                    # 接收验证码并填入
                    # 对该号码无法收到验证码进行异常处理
                    # while True:
                    verify_code = getverifysms.getverifycode(str(order_id))  # 获取验证码
                    if verify_code is not None:  # 获取到验证码
                        self.driver.find_element_by_xpath('//input[@name="code"]').click()
                        self.driver.find_element_by_xpath('//input[@name="code"]').clear()
                        for verify_code_each in verify_code:
                            self.driver.find_element_by_xpath('//input[@name="code"]').send_keys(verify_code_each)  # 填入手机验证码
                            time.sleep(random.random())  # 暂停0-1秒之间随机时间
                        time.sleep(random.randint(15, 30))
                        break
                    else:  # 获取验证码得到None的结果
                        getverifysms.cancel(str(order_id))  # 获取验证码超过检测次数,认为未检测到验证码
                        self.driver.find_element_by_xpath('//*[@class="FliLIb n4P87"]').click()  # 点击后退返回到填写手机号页面
                        time.sleep(random.randint(5, 10))
                        self.driver.find_element_by_xpath('//input[@type="tel"]').clear()  # 清空号码输入框内容
                        time.sleep(random.randint(5, 10))
                        pass

            # 模拟鼠标点击下一步
            next_step3 = self.driver.find_element_by_xpath('//*[@class="FliLIb DL0QTb"]')  # 点击下一步
            mouse_action.click(next_step3)
            mouse_action.perform()
            time.sleep(random.randint(10, 20))

            # 下一个页面内容填写
            # 邮件列表
            email_list = ['xxx@qq.com', 'xxx@163.com']
            # 年份列表
            year_list = []
            j = 0
            while j < 25:
                year = 1980 + j
                year_list.append(str(year))
                j += 1
            year = random.choice(year_list)
            # 填写辅助邮箱
            verify_mail = random.choice(email_list)
            # self.driver.find_element_by_xpath('//input[@name="recoveryEmail"]').send_keys(verify_mail)
            time.sleep(random.randint(5, 10))
            for year_each in year:
                self.driver.find_element_by_xpath('//input[@name="year"]').send_keys(year_each)  # 随机填写生日年份
                time.sleep(random.random())  # 暂停0-1秒之间随机时间
            time.sleep(random.randint(5, 10))
            month_select = Select(self.driver.find_element_by_xpath('//*[@id="month"]'))
            time.sleep(random.randint(5, 10))
            month_number = random.randint(1, 12)
            month_select.select_by_index(month_number)  # 随机选择一个月份

            # 日期列表
            day_list = []
            k = 0
            while k < 28:
                day = 1 + k
                day_list.append(str(day))
                k += 1
            day = random.choice(day_list)
            time.sleep(random.randint(5, 10))
            for day_each in day:
                self.driver.find_element_by_xpath('//input[@name="day"]').send_keys(day_each)  # 填写日期
                time.sleep(random.random())  # 暂停0-1秒之间随机时间
            time.sleep(random.randint(5, 10))
            # 选择性别
            gender_select = Select(self.driver.find_element_by_xpath('//*[@id="gender"]'))
            gender_number = random.randint(1, 3)
            gender_select.select_by_index(gender_number)  # 填写性别
            time.sleep(random.randint(5, 10))
            # 点击下一步
            next_step4 = self.driver.find_element_by_xpath('//*[@class="FliLIb DL0QTb"]')  # 点击下一步
            mouse_action.click(next_step4)
            mouse_action.perform()
            time.sleep(random.randint(5, 10))

            # 跳过'充分利用您的电话号码'
            jump_step1 = self.driver.find_element_by_xpath('//*[@class="FliLIb DL0QTb"]')  # 点击'跳过'
            mouse_action.click(jump_step1)
            mouse_action.perform()
            time.sleep(random.randint(5, 10))
            # 同意"隐私权及条款"
            ok_step1 = self.driver.find_element_by_xpath('//*[@class="FliLIb DL0QTb"]')  # 点击'我同意'
            mouse_action.click(ok_step1)
            mouse_action.perform()
            time.sleep(random.randint(10, 30))

            # 整理账号信息 : 邮箱账号,ip地址,注册手机号,密码,年月日,性别,验证邮箱
            account_data = [usrname_str_true + '@gmail.com', str(phone_number), psw_value, str(year) + '.' + str(month_number) + '.' + str(day), verify_mail]

            # 账号信息添加进google账号文档
            with open('./google账号表.csv', 'a+', newline='') as f1:
                csv_data = csv.writer(f1)
                # 读取文件判断表头是否存在
                with open('./google账号表.csv', 'r', encoding='gb18030', errors='ignore') as f2:
                    reader = csv.reader(f2)
                    if not [row for row in reader]:
                        # 写入表头
                        csv_head = ['邮箱账号', '注册手机号', '密码', '年月日', '验证邮箱']
                        csv_data.writerow(csv_head)
                        csv_data.writerow(account_data)
                    else:
                        # 跳过表头
                        csv_data.writerow(account_data)
            self.driver.close()  # 关闭浏览器
        except Exception as e:
            print(e)
            self.driver.close()


def sign_up():
    app = Google_signup()
    app.sign_up_now()


if __name__ == "__main__":
    while True:
        sign_up()
        time.sleep(5)

其中ip_get_foreigh模块代码

import pandas as pd
import requests
from bs4 import BeautifulSoup

ip_url_list = []

def getip():
    for i in range(1, 4):
        url = 'http://www.ip3366.net/free/?stype=3&page=' + str(i)
        headers = {
        	'自己设置'
            }
        re = requests.get(url, headers=headers)
        re.encoding = "gb2312"
        soup = BeautifulSoup(re.text, 'html.parser')
        ip_datas = soup.find('table')
        df_tables = pd.read_html(str(ip_datas))
        for j in range(len(df_tables)):
            df = df_tables[j]
            df_ip_list = df['IP'].tolist()
            df_port_list = df['PORT'].tolist()
            df_http_type = df['类型'].tolist()
            df_location_list = df['位置'].tolist()
            if len(df_ip_list) == len(df_port_list):
                for i in range(len(df_ip_list)):
                    ip_url = df_http_type[i].lower() + '://' + str(df_ip_list[i]) + ':' + str(df_port_list[i])
                    ip_country = df_location_list[i]
                    ip_url_data = [ip_url, ip_country]
                    ip_url_list.append(ip_url_data)
    return ip_url_list


'''if __name__ == '__main__':
    getip()'''

如上。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爬吧爬吧

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值