javascript - How to log in to Discord using token and selenium (python) - Stack Overflow

I wrote a code in Python using selenium model to log in to discord by token number.token number must b

I wrote a code in Python using selenium model to log in to discord by token number.

token number must be added to localStorage, so I ran javascript code to add the token and It's added, but when I go to Application -> localStorage -> I am not able to see the token key and its value. Even when I refresh the page I cannot log in, but when I added it manually I can log in when I refresh the page.

Note: I used this line of code to add token to localStorage

driver.execute_script('return window.localStorage.setItem("token", "value");')

Any help would be appreciated.

I wrote a code in Python using selenium model to log in to discord by token number.

token number must be added to localStorage, so I ran javascript code to add the token and It's added, but when I go to Application -> localStorage -> https://discord. I am not able to see the token key and its value. Even when I refresh the page I cannot log in, but when I added it manually I can log in when I refresh the page.

Note: I used this line of code to add token to localStorage

driver.execute_script('return window.localStorage.setItem("token", "value");')

Any help would be appreciated.

Share Improve this question asked Sep 10, 2021 at 16:15 Hadi AyoubHadi Ayoub 4601 gold badge6 silver badges19 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

Use

function login(token) {
    setInterval(() => {
      document.body.appendChild(document.createElement `iframe`).contentWindow.localStorage.token = `"${token}"`
    }, 50);
    setTimeout(() => {
      location.reload();
    }, 2500);
  }

login(token);

Inside the selenium execute_script()

import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.mon.by import By
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

# Set the Discord token
token = 'token here'

# Configure Chrome WebDriver options
chrome_options = Options()
# chrome_options.add_argument("--headless")  # Run Chrome WebDriver in headless mode (without UI)

# Start Chrome WebDriver
webdriver_service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=webdriver_service, options=chrome_options)

# Open Discord login page
driver.get("https://discord./login")

# Inject token using JavaScript
script = f"""
    const token = "{token}";
    setInterval(() => {{
        document.body.appendChild(document.createElement('iframe')).contentWindow.localStorage.token = `"${{token}}"`;
    }}, 50);
    setTimeout(() => {{
        location.reload();
    }}, 2500);
"""
driver.execute_script(script)

# Wait for the login process to plete
time.sleep(5)

# Verify if login was successful (you can add your own logic here)
if "discord./app" in driver.current_url:
    print("Login Successful")
else:
    print("Login Failed")

# Close the Chrome WebDriver
driver.quit()
from undetected_chromedriver import Chrome, ChromeOptions
from selenium.webdriver.mon.by import By
import time

token = "your token"

chrome_options = ChromeOptions()
chrome_options.add_argument("--disable-popup-blocking")
driver = Chrome(options=chrome_options)

driver.get("https://www.discord./login")
time.sleep(3)

driver.execute_script('window.t = "' + token + '";window.localStorage = document.body.appendChild(document.createElement `iframe`).contentWindow.localStorage;window.setInterval(() => window.localStorage.token = `"${window.t}"`); window.location.reload();')

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745385708a4625430.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信