Jump to content
ICEBREAKER101010

Python selenium login method

Recommended Posts

Salutare tuturor.

 

As avea si eu nevoie de ceva ajutor in legatura cu un script facut un python. Scriptul respectiv se logheaza pe un site anume si creeaza un fisier denumit cookies.

Ideea e ca nu prea reusesc sa il fac sa functioneze

 

 

 

from __future__ import unicode_literals
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait

import sys, time
import youtube_dl
import os


username = sys.argv[1]
pwd = sys.argv[2]
url = sys.argv[3] 
cookie_file = 'cookies.txt'

print("Don't touch this one")

# remove cookie file if it exists
if os.path.exists( cookie_file 😞
   os.remove( cookie_file )

# recreate file and open in append mode
f = open( cookie_file, 'a+')

# cookie function
def get_cookies():
  expiry = 0
  for i in driver.get_cookies():
    if not i.get('expiry'):
        expiry = 0
    else:
        expiry = i.get('expiry')
    cookie = '{}\t{}\t{}\t{}\t{}\t{}\t{}\n'.format( i['domain'], str( i['httpOnly'] ).upper(), i['path'], str( i['secure'] ).upper(), expiry, i['name'], i['value'] )
    f.write( cookie )

# chrome options
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--window-size=1280,720")

# initiate browser 
driver = webdriver.Chrome( options=options )

# navigate to ine
driver.get("http://members.ine.com/")
driver.implicitly_wait(10)

# click login link
link = find_element_by_class_name("form-group")
link.click()
# get cookies from members.ine.com
print("Getting cookies from members.ine.com/auth/login")
get_cookies()

# wait until login screen appears 
print("Sleeping for 5 seconds..")
time.sleep(5)

print("Attempting to login..")
user = driver.find_element_by_name('email')
user.send_keys( username )
password = driver.find_element_by_name('password')
password.send_keys( pwd )
password.send_keys(Keys.RETURN)


Multumesc!

Link to comment
Share on other sites

19 hours ago, u0m3 said:
  1. Vezi ca este un buton special pentru inserat cod intr-un post
  2. Ce nu reusesti sa faci sa mearga? Pentru salvat/incarcat cookies incearca https://stackoverflow.com/questions/15058462/how-to-save-and-load-cookies-using-python-selenium-webdriver

Salut. Am reusit sa il fac sa functioneze.Se logheaza cum trebuie, salveaza cookies si le transforma in cookies pentru curl(de care are nevoie youtube-dl) dar nu merge sa downloadez videourile de pe cloudacademy. Probabil mai trebuie ceva cod pentru a extrage linkurile cu videouri din pagina unde se afla un anumit curs.Asa de downloadat, merge cu IDM dar vreau ceva automat.

Ma doare mana sa dau atatea clickuri :D

 

Multumesc!

Edited by ICEBREAKER101010
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...