首页 > 解决方案 > 我制作了一个在 python3 中使用 selenium 发送消息的脚本,但它不起作用

问题描述

这是我的脚本(https://pastebin.com/dWLFvirn)。我已经使用终端运行脚本,但它显示错误。这是屏幕截图(https://ibb.co/NSfLgL8

我想使用“ https://getlinks.info/slam-book/p/Shubha ”作为它必须工作的链接。

我的系统配置是=>> 1. Kali Linux 2020.1b 32-Bit , 2. Python 3.7.5

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import hashlib
import string
import random

driver_location = "/home/kali/Desktop/geckodriver"

print('''\033[34m Starting Attack \033[34m''')

for i in range(10):


    driver=webdriver.Firefox(executable_path=driver_location)
    driver.get("https://getlinks.info/slam-book/p/Shubha")

    driver.implicitly_wait(60)

    firstbtn = driver.find_element_by_xpath('/html/body/div[1]/center/a[1]')
    firstbtn.click()

    firsttxtbx = driver.find_element_by_xpath('//*[@id="nametb"]')
    firsttxtbx.send_keys('I am Blackghost')

    scndbtn = driver.find_element_by_xpath('/html/body/div[2]/center/a')
    scndbtn.click()

    secondtxtbx = driver.find_element_by_xpath('//*[@id="ipQ0"]')
    secondtxtbx.send_keys('I have told you not to indulge in this websites')

    thdbtn = driver.find_element_by_xpath('/html/body/div[3]/center/div/div[1]/a')
    thdbtn.click()

    thirdtxtbx = driver.find_element_by_xpath('//*[@id="ipQ1"]')
    thirdtxtbx.send_keys('This websites allow multiple entry flaw.')

    frthbtn = driver.find_element_by_xpath('/html/body/div[3]/center/div/div[2]/a')
    frthbtn.click()

    fourthtxtbx = driver.find_element_by_xpath('//*[@id="ipQ2"]')
    fourthtxtbx.send_keys('Which is actually a vulnability')

    fthbtn = driver.find_element_by_xpath('/html/body/div[3]/center/div/div[3]/a')
    fthbtn.click()

    fifthtxtbx = driver.find_element_by_xpath('//*[@id="ipQ3"]')
    fifthtxtbx.send_keys('You must not use these types of websites.')

    sixthbtn = driver.find_element_by_xpath('/html/body/div[3]/center/div/div[4]/a')
    sixthbtn.click()

    sixthtxtbx = driver.find_element_by_xpath('//*[@id="ipQ4"]')
    sixthtxtbx.send_keys('And don\'nt ever share this types of links in any social medias. ')

    svnthbtn = driver.find_element_by_xpath('/html/body/div[3]/center/div/div[5]/a')
    svnthbtn.click()

    seventhtxtbx = driver.find_element_by_xpath('//*[@id="ipQ5"]')
    seventhtxtbx.send_keys('Specially in Whatsapp')

    eighthbtn = driver.find_element_by_xpath('/html/body/div[3]/center/div/div[6]/a')
    eighthbtn.click()

    eighthtxtbx = driver.find_element_by_xpath('//*[@id="ipQ6"]')
    eighthtxtbx.send_keys('We are Anonymous. We are legion.')

    nthbtn = driver.find_element_by_xpath('/html/body/div[3]/center/div/div[7]/a')
    nthbtn.click()

    ninethtxtbx = driver.find_element_by_xpath('//*[@id="ipQ7"]')
    ninethtxtbx.send_keys('We donot forget. We donot forgive.')

    tnthbtn = driver.find_element_by_xpath('/html/body/div[3]/center/div/div[8]/a')
    tnthbtn.click()

    tenthtxtbx = driver.find_element_by_xpath('//*[@id="ipQ8"]')
    tenthtxtbx.send_keys('You must have to give these warnings in whatsapp status.')

    elvnthbtn = driver.find_element_by_xpath('/html/body/div[3]/center/div/div[9]/a')
    elvnthbtn.click()

    send_finish = driver.find_element_by_xpath('/html/body/div[2]/div/div[3]/button[1]')
    send_finish.click()

    driver.close()
    driver.quit()

    print('Attack finished',i)

----------------------------------------------------------------------------------------------------

标签: pythonhtmlseleniumpython-3.6

解决方案


我已经使用 chrome 浏览器尝试了您的代码,希望它也可以在 firefox 上运行。要解决这个问题,您必须在向您的输入发送密钥之前诱导 WebDriverWait 元素可点击。

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as Wait

driver = webdriver.Chrome(executable_path=r" path to chromedriver.exe")
driver.maximize_window()


    driver.get("https://getlinks.info/slam-book/p/Shubha")
    main_window = driver.current_window_handle
    wait = WebDriverWait(driver, 20)

    wait.until(EC.element_to_be_clickable((By.XPATH, "//a[@class='button no-border-radius is-fullwidth is-medium animated infinite pulse']"))).click()

    wait.until(EC.element_to_be_clickable((By.ID, "nametb"))).send_keys('I am Blackghost')

在此处输入图像描述

更新的解决方案:

driver.get("https://getlinks.info/slam-book/p/Shubha")

wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[@class='button no-border-radius is-fullwidth is-medium animated infinite pulse']"))).click()
wait.until(EC.element_to_be_clickable((By.ID, "nametb"))).send_keys('I am Blackghost')
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(),'Next')]"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='ipQ0']"))).send_keys('I have told you not to indulge in this websites')
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='divQ0']//a[contains(@class,'button no-border-radius is-fullwidth is-medium')][contains(text(),'Next')]"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='ipQ1']"))).send_keys('This websites allow multiple entry flaw.')
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='divQ1']//a[contains(@class,'button no-border-radius is-fullwidth is-medium')][contains(text(),'Next')]"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='ipQ2']"))).send_keys('Which is actually a vulnability')
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='divQ2']//a[contains(@class,'button no-border-radius is-fullwidth is-medium')][contains(text(),'Next')]"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='ipQ3']"))).send_keys('You must not use these types of websites.')
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='divQ3']//a[contains(@class,'button no-border-radius is-fullwidth is-medium')][contains(text(),'Next')]"))).click()


wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='ipQ4']"))).send_keys('And don\'nt ever share this types of links in any social medias.')
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='divQ4']//a[contains(@class,'button no-border-radius is-fullwidth is-medium')][contains(text(),'Next')]"))).click()


wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='ipQ5']"))).send_keys('Specially in Whatsapp')
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='divQ5']//a[contains(@class,'button no-border-radius is-fullwidth is-medium')][contains(text(),'Next')]"))).click()


wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='ipQ6']"))).send_keys('We are Anonymous. We are legion.')
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='divQ6']//a[contains(@class,'button no-border-radius is-fullwidth is-medium')][contains(text(),'Next')]"))).click()


wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='ipQ7']"))).send_keys('We donot forget. We donot forgive.')
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='divQ7']//a[contains(@class,'button no-border-radius is-fullwidth is-medium')][contains(text(),'Next')]"))).click()


wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='ipQ8']"))).send_keys('You must have to give these warnings in whatsapp status.')
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(),'Finish')]"))).click()

输出 :

在此处输入图像描述


推荐阅读