Forums

Discord Selenium

Hello , When i try this code , my selenium stucks at the discord loading screen.(i am checking the screen with screenshot method.

Thanks

from selenium import webdriver
from selenium.webdriver.common.by import By
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
import time



driver = webdriver.Chrome(options=chrome_options)
driver.get("http://discord.com/login")
print("waiting")
time.sleep(10)

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

login('discord token here')"""


driver.execute_script(komut)
print("executed")
time.sleep(5)
driver.get("http://discord.com/channels/@me")

You need to inspect the state of the thing that you want to interact with.

I am using dev console to login to my acc.

my problem : discord main page is not loading after logged in to my account.

Screenshot : https://ibb.co/XSyDQn2

It looks like a Discord behavior -- maybe they don't want to be scraped, or maybe you need to click on some element to make this page disappear.

When i try on my pc , it works. And if you look down of the screen , you will see "Connection Problems? Let Us Know" .

I think , problem is pythonanywhere cant connect to discord.

Please fix this problem.

I need help of the Hero. :)

As pafk said. Discord could be actively preventing from being interacted with like that.

:/ but script working on my computer.

I really need to solve this problem.

Problem : Selenium cant connect to discord normally (gives This error , look down of the screenshot)

Some services don't want to be accessed like that from known headless servers like ours.