So basically i am working on a python script that loggs into a twitch account and stays there to generate a viewer.
But my main issue is how do i make this work for multiple accounts.
How to hide alle the Windows, and how can i handle multiple selenium windows ?
Is selenium even good for that or is there a other way ?
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--mute-audio")
driver = webdriver.Chrome("D:\Downloads\chromedriver_win32\chromedriver.exe", chrome_options=chrome_options)
driver.minimize_window()
driver.get('https://www.twitch.tv/login')
search_form = driver.find_element_by_id('login-username')
search_form.send_keys('user')
search_form = driver.find_element_by_id('password-input')
search_form.send_keys('password')
search_form.submit()
driver.implicitly_wait(10)
driver.get('https://www.twitch.tv/channel')
You are definitely able to use Selenium and Python to do this. To run multiple accounts, you will have to utilize multi-threading or create multiple driver objects to manage.
Multithreading example from this thread:
from selenium import webdriver
import threading
import time
def test_logic():
driver = webdriver.Firefox()
url = 'https://www.google.co.in'
driver.get(url)
# Implement your test logic
time.sleep(2)
driver.quit()
N = 5 # Number of browsers to spawn
thread_list = list()
# Start test
for i in range(N):
t = threading.Thread(name='Test {}'.format(i), target=test_logic)
t.start()
time.sleep(1)
print t.name + ' started!'
thread_list.append(t)
# Wait for all thre<ads to complete
for thread in thread_list:
thread.join()
print 'Test completed!'
Each driver will have to use a proxy connection to connect to Twitch on separate IP addresses. I suggest using Opera as it has a built in VPN, makes it a lot easier.
Example of Opera and Selenium from this thread:
from selenium import webdriver
from time import sleep
# The profile directory which Opera VPN was enabled manually using the GUI
opera_profile = '/home/user-directory/.config/opera'
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=' + opera_profile)
driver = webdriver.Opera(options=options)
driver.get('https://whatismyipaddress.com')
sleep(10)
driver.quit()
To hide the console for webdrivers you must run them with the "headless" option.
Headless for chrome driver.
from selenium import webdriver from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
Unfortunately headless is not supported in Opera driver, so you must use Chrome or Firefox for this.
Good luck!
hi you will not be able to create a bot with selenium because even if you manage to connect several accounts on the twitch account, twitch (like youtube) have a system that looks at your IP address and does not increase the number of views if the multiple connection come from the same computer.
Related
I am trying to acces whatsapp web with python without having to scan the QR code everytime I restart the program (because in my normal browser I also dont have to do that). But how can I do that? Where is the data stored that tells whatsapp web to connect to my phone? And how do I save this data and send it to the browser when I rerun the code?
I already tried this because someone told me I should save the cookies:
from selenium import webdriver
import time
browser = None
cookies = None
def init():
browser = webdriver.Firefox(executable_path=r"C:/Users/Pascal/Desktop/geckodriver.exe")
browser.get("https://web.whatsapp.com/")
time.sleep(5) # in this time I scanned the QR to see if there are cookies
cookies = browser.get_cookies()
print(len(cookies))
print(cookies)
init()
Unfortunately there were no cookies..
The output was 0 and [].
How do I fix this probblem?
As mentioned in the answer to this question, pass your Chrome profile to the Chromedriver in order to avoid this problem. You can do it like this:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profile
driver = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe", options=options)
This one works for me, I just created a folder, on the home directory of the script and a little modifications and it works perfectly.
###########
E_PROFILE_PATH = "user-data-dir=C:\Users\Denoh\Documents\Project\WhatBOts\SessionSaver"
##################
This is the Config File that I will import later
##################
The main script starts here
##################
from selenium import webdriver
from config import E_PROFILE_PATH
options = webdriver.ChromeOptions()
options.add_argument(E_PROFILE_PATH)
driver = webdriver.Chrome(executable_path='chromedriver_win32_86.0.4240.22\chromedriver.exe', options=options)
driver.get('https://web.whatsapp.com/')
I am currently only able to access my school computers which do not allow downloads. I am trying to run selenium with mutable threads through a web-based python application. For example I have tried repl.it and online Juypterlab but have trouble. For example my code looks like this for real.it...
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import _thread
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
def thread1():
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://www.youtube.com")
def thread2():
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://www.google.com")
_thread.start_new_thread(thread1, ())
_thread.start_new_thread(thread2, ())
my attempted juypterlab code looks like...
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import _thread
def thread1():
driver = webdriver.Chrome('/Applications/chromedriver')
driver.get("https://www.youtube.com")
def thread2():
driver = webdriver.Chrome('/Applications/chromedriver')
driver.get("https://www.google.com")
_thread.start_new_thread(thread1, ())
_thread.start_new_thread(thread2, ())
my issue with repl.it is that I can not get mutable threads and with the online juypterlab I cannot get the path for my chromedriver to work. How can I get mutable treads of selenium to work at once while in a web-based environment? I think the main issue is not being able to get the PATH on a web-based application.
I have this code that I run from two different files in two different consoles in Spyder. I need to do different tasks with each browser but it does create a second driver, the second instance of the script just use the first browser... How to separate the tasks and have two browser please ? I thought two different consoles was multithreading, this is not the case ?
chrome_options = Options()
chrome_options.add_argument("--user-data-dir=chrome-data")
try:
browser = webdriver.Chrome(options=chrome_options)
except SessionNotCreatedException:
os.environ['WDM_LOG_LEVEL'] = '0'
browser = webdriver.Chrome(ChromeDriverManager().install(), options=chrome
browser.get('http://google.com')
I don't know if it is what you wanted but you can have 2 different browsers with that code for example :
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver1 = webdriver.Chrome()
driver2 = webdriver.Chrome()
driver1.get('https://www.google.com/?gws_rd=ssl')
driver2.get('https://stackoverflow.com/')
Hope I helped :)
Hope this solve your problem.
from selenium import webdriver
amount = int(input('[?] amount browsers '))
driver = []
while amount != len(driver):
driver.append(webdriver.Chrome())
# if u want the to make a ctrl+c ctrl+v browser use this down here
for i in range(len(driver)):
driver[i].get('https://www.google.com/')
#else use this
driver[0].get('https://www.google.com/')
driver[1].get('https://stackoverflow.com/')
When selenium opens youtube, I am not signed in and when I try to sign in, it says the following:
"This browser or app may not be secure. Learn more
Try using a different browser. If you’re already using a supported browser, you can refresh your screen and try again to sign in."
Is there any way to sign in
This is the code:
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
browser = webdriver.Chrome("C:\\Users\\Pranav Sandeep\\Downloads\\chromedriver.exe")
browser.get('https://www.youtube.com')
SearchBar = browser.find_element_by_name("search_query").send_keys("Selenium", Keys.ENTER)
Video = browser.find_element_by_id("video-title")
Video.click()
You need to first sign in to google and then you can go to youtube. Use this code below.
Use Seleniumwire with undetected browser v2
Note: put chromedriver in your sys path.
from seleniumwire.undetected_chromedriver.v2 import Chrome, ChromeOptions
import time
options = {}
chrome_options = ChromeOptions()
chrome_options.add_argument('--user-data-dir=hash')
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--disable-dev-shm-usage")
# chrome_options.add_argument("--headless")
browser = Chrome(seleniumwire_options=options, options=chrome_options)
browser.get('https://gmail.com')
browser.find_element_by_xpath('//*[#id="identifierId"]').send_keys('your-email')
browser.find_element_by_xpath('//*[#id="identifierNext"]/div/button').click()
time.sleep(5)
browser.find_element_by_xpath('//*[#id="password"]/div[1]/div/div[1]/input').send_keys('you-password')
browser.find_element_by_xpath('//*[#id="passwordNext"]/div/button').click()
time.sleep(5)
browser.get('https://www.youtube.com')
In addition to this, selenium wire has many awesome features, check out Github repository
I've been attempting to bypass using Spectron for End2End testing an electron application by leveraging my experience with Selenium Webdriver on Python.
Using a combination of the Chromedriver get started page, and several resources that seem to suggest its possible, this is what I came up with:
from selenium import webdriver
import selenium.webdriver.chrome.service as service
servicer = service.Service('C:\\browserDrivers\\chromedriver_win32\\chromedriver.exe')
servicer.start()
capabilities = {'chrome.binary': 'C:\\path\\to\\electron.exe'}
remote = webdriver.remote.webdriver.WebDriver(command_executor=servicer.service_url, desired_capabilities = capabilities, browser_profile=None, proxy=None, keep_alive=False
The issue is that instead of opening the electron application, it opens a standard instance of Chrome.
Most of resources I've seen have been several years old so something may have changed to make it no longer possible.
Does anyone know of a way to use Python Selenium WebDriver to test an Electron application?
Below works great for me
from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location = "/Applications/Electron.app/Contents/MacOS/Electron"
driver = webdriver.Chrome(chrome_options=options)
driver.get("http://www.google.com")
driver.quit()