P
P
puszkin2019-12-15 21:41:43
Python
puszkin, 2019-12-15 21:41:43

Twitter. How many times to randomly follow Python Selenium?

There is a page in followers (followers). What commands do you need to write commands in order to:
1) Follow everyone who is on the page, do not click if there is already a
follower 2) Randomly follow from (1000 for example) 100 pieces found.
*3) Follow, depending on how many followers this user has (for example, if more than 1000, then follow). Most likely you need to go from the list of followers to each account and then go back

# -*- coding: utf-8 -*-
from selenium import webdriver
    from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, re, time,random,datetime,os,errno,traceback;






wait_1 = 3


def test_app_dynamics_job():
    try:
        login = 'login' #login
        password = 'password' #password
        dop = 'dop' #dop
    
    except Exception as exc:
        print(' № ошибка!')
        print(exc)
        traceback.print_exc() 
        


    driver = webdriver.Chrome()
    ################!!!!!!!!########### ! НАЧАЛО вставка кода с коммандами селениум

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

    time.sleep(wait_1 + 3)
    print('зашел на сайт...')
    driver.find_element_by_xpath("(//input[@name='session[username_or_email]'])[2]").send_keys(login)
    time.sleep(wait_1 + 3)
    driver.find_element_by_xpath("(//input[@name='session[password]'])[2]").send_keys(password)
    time.sleep(wait_1 + 3)
    driver.find_element_by_xpath(u"(.//*[normalize-space(text()) and normalize-space(.)='Войти'])[2]/following::button[1]").click()

    
    time.sleep(wait_1 + 3)
    

    #если вылезает дополнительный вопрос
    try: 
        
        driver.find_element_by_id("challenge_response").send_keys(dop)
        driver.find_element_by_id("email_challenge_submit").click()
        
    except Exception as exc:
        print(exc)
        traceback.print_exc()



    #_+_+_+_+_+_
    #пробуем нажать на одну из конопок если выходит, лишние кнопки
    try:
        try:
            driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Welcome!'])[1]/following::span[6]").click()
        except Exception as exc:
            print(exc)
            traceback.print_exc()
        try:
            driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Lights out'])[1]/following::span[2]").click()
        except Exception as exc:
            print(exc)
            traceback.print_exc()
        #окно пишеться новые правила и все такое. Нажать на ОК
        try:
            driver.find_element_by_xpath(u"(.//*[normalize-space(text()) and normalize-space(.)='will be in effect. Now’s a great chance to review them.'])[1]/following::span[3]").click()
        except Exception as exc:
            print(exc)
            traceback.print_exc()
    except Exception as exc:
        print(exc)
        traceback.print_exc()        
        #другие комманды
   
   #start
    
    #element.
    #/html/body/div/div/div/div/main/div/div/div/div[1]/div/div[4]/div/div/section/div/div/div/div[12]/div/article/div/div[2]/div[2]/div[4]/div[3]/div/div/div[2]
    #/html/body/div[1]/div/div/div/main/div/div/div/div[1]/div/div[4]/div/div/section/div/div/div/div[12]/div/article/div/div[2]/div[2]/div[4]/div[3]/div/div/div[2]/span/span
    #>MATCH><div class="css-1dbjc4n r-xoduu5 r-1udh0
                            
            
            
                
                #_+_+_+_+_+_
    
            
            
            
           

try:
    test_app_dynamics_job()
    
except Exception as exc:
    print(exc)
    traceback.print_exc()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question