4

The problem is Twitch authorization using Selenium in Python. Help, all day I can not solve the problem. Tried different browsers, selenium undetected. Error "Your browser is not yet supported. Use the recommended browser or learn more". Who else has this error? How to fix it?

If your authorization is successful, please share how to do it.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
import time
import json
import re
import os

PATH = os.path.join(os.path.join(os.path.join(os.getcwd()))).replace('/','//')

options = Options()
options.headless = False
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36")
options.add_argument('--ignore-ssl-errors')
options.add_argument('--no-sandbox')
options.add_argument("--disable-blink-features")
options.add_argument("--disable-blink-features=AutomationControlled")

driver = webdriver.Chrome(executable_path=r'{0}\\chromedriver.exe'.format(PATH),options=options)
driver.get("https://www.twitch.tv/")

driver.find_element_by_xpath('//*[@id="root"]/div/div[2]/nav/div/div[3]/div[3]/div/div[1]/div[1]/button/div/div').click()

self.driver.find_element_by_xpath('//*[@id="login-username"]').send_keys(login)
self.driver.find_element_by_xpath('//*[@id="password-input"]').send_keys(password)

self.driver.find_element_by_css_selector('button[data-a-target="passport-login-button"]').click()
  1. Tried various browsers
  2. Different accounts Twitch
  3. Selenium undetected
iPython
  • 41
  • 2
  • I also did all the similar things. Also tried pyautogui but never worked. If some wishes to pick up the pace. here is all my code https://t.ly/TWka – rick Jan 15 '23 at 14:01
  • Thanks for the code, does it work for you? – iPython Jan 15 '23 at 20:50
  • No it dosen't. I even tried to launch the selenium browser and do res of the task manually. But it wont let me do that too. – rick Jan 15 '23 at 21:29
  • To me it works without any problem, which is the line of code raising the error? – sound wave Jan 16 '23 at 09:54
  • can you login? when I press the login button, it says that the browser is outdated, what version of Selenium do you have? What browser did you try? which version? – iPython Jan 16 '23 at 10:01
  • Oh sorry I did not click the button, yes i have the problem too, check the answer for a possible alternative – sound wave Jan 16 '23 at 13:03

1 Answers1

0

I tried with chrome, firefox and edge drivers but they all have the same problem, maybe the site detects the use of selenium. The only way I see is to create a new chrome profile on the normal browser, login to twitch and then use its cookies in selenium, in this way when the page is loaded in selenium you will be already logged in.

As a drawback, if you want to login using several accounts, you need a chrome profile for each of them (you can also use a single profile but this will require to log out the current account and login another account each time you want to use a different account).

  1. To create a new profile, open your chrome browser, click on the profile icon on top right, then click "Add" and then click "Continue without an account".

enter image description here

  1. Then write a name for your profile and be sure check the box "Create a desktop shortcut". I suggest you to choose a color so that you will immediately see if it works when selenium open the browser window.

enter image description here

  1. Open the chrome from the new desktop icon (mine is called "PythonSelenium - Chrome.exe") and login to twitch. It is possible that it asks you to verify your identity by entering a code sent to your email.

    After you logged in, close the browser and open the properties of the new desktop shortcut. Take note of the name of the profile directory, which in my case is "Profile 3".

enter image description here

  1. Now we have to tell selenium to open the chrome driver using this new profile we've just created, which is logged in twitch. To do this we need the path of the folder where the profile is stored. By default the path is something like C:\Users\your_username\AppData\Local\Google\Chrome\User Data, if you are not sure about it check where chrome is installed in your computer.

Then run this code (remember to substitute Profile 3 with the name of your profile from step 3)

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\your_username\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument("profile-directory=Profile 3") # <-- substitute Profile 3 with your profile name
chromedriver_path = '...'
driver = webdriver.Chrome(options=options, service=Service(chromedriver_path))
driver.get('http://twitch.tv/login') # it should redirect you to the homepage

And this is the result. Notice that since we are already logged in, when loading the page http://twitch.tv/login we were redirected to the homepage. Notice also that the color of the browser is the one chosen during the creation of the profile.

enter image description here

sound wave
  • 3,191
  • 3
  • 11
  • 29
  • Thanks for your reply 1. Is it possible to create many profiles in one browser? if I want to reconnect between accounts? 2. Cookies can expire over time, do you need to log in again? – iPython Jan 16 '23 at 14:09
  • @iPython (1) yes i suggest to create one profile for each twitch account, and name each chrome profile with the corresponding twitch username to avoid confusion (2) I guess yes, if this happens you have to login in the normal chrome browser using the profile corresponding to the twitch account – sound wave Jan 16 '23 at 14:24
  • I understand, thanks, for 1000 accounts this is not an option, constantly monitor authorization – iPython Jan 16 '23 at 14:29
  • Made with pyautogui using proxy – iPython Jan 22 '23 at 21:51
  • @iPython Good! You may consider adding an answer and put the code there so that others can use it – sound wave Feb 01 '23 at 13:44
  • How would you do this if you Google data is synced? - that is your user data is not stored on your C drive - Chrome Sync does not store your data in a single, easily downloadable file. – GDog Aug 29 '23 at 11:23