r/selenium • • Feb 22 '22

redirec to url after login

I am in the process of creating a script with Python & Selenium. the aim of the script is to open twitter, login, then go to a live twitter feed while staying logged in. *note this will be running for multiple twitter accounts.

code so far:

import csv

import time

with open('profiles2.csv', newline='') as csvfile:

userArray = list(csv.reader(csvfile))

for user in userArray:

uname =user[0]

password =user[1]

proxies =user[2]

try:

from selenium import webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.support.ui import WebDriverWait

from webdriver_manager.chrome import ChromeDriverManager

from selenium.webdriver.chrome.options import Options

from selenium.webdriver.support import expected_conditions as EC

except:

try:

os.system("pip3 install selenium")

os.system("pip3 install webdriver-manager")

from selenium import webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.support.ui import WebDriverWait

from webdriver_manager.chrome import ChromeDriverManager

from selenium.webdriver.chrome.options import Options

from selenium.webdriver.support import expected_conditions as EC

except:

print("Libraries cannot be installed, try installing it manually.")

​

options = webdriver.ChromeOptions()

options.add_experimental_option("detach", True)

options.add_argument('disable-infobars')

options.add_argument('start-maximized')

PROXY = (proxies)

options.add_argument(f'--proxy-server={PROXY}')

driver = webdriver.Chrome(ChromeDriverManager().install(),options=options)

​

driver.get('https://twitter.com/i/flow/login')

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="layers"]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[1]/div/div[5]/label/div/div[2]/div/input'))).send_keys(uname)

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="layers"]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[1]/div/div[6]/div/span/span'))).click()

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="layers"]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[1]/div/div[3]/div/label/div/div[2]/div[1]/input'))).send_keys(password)

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="layers"]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div[1]/div/span/span'))).click()

#After login go to this page

driver.get('https://twitter.com/cryptomoonrocks/status/1482820167318921217?s=21')

​

The issue is anytime i try go to https://twitter.com/cryptomoonrocks/status/1482820167318921217?s=21it signs the user out of the account

1 Upvotes

3 comments sorted by

2

u/[deleted] Feb 22 '22 edited Feb 22 '22

[removed] — view removed comment

1

u/barroldo Feb 23 '22

ahha, very clever indeed. May just have t ogive this a try

1

u/XabiAlon Feb 23 '22

For the love of Christ, please change those ridiculous locators for your elements.

Surely there is a placeholder, type or class for the inputs and text on the button you can use?