1

In my python script, I input 3 pieces of data, call them A, B, C. I want to input the data in arrays, for example, arrayA = [A1, A2 ... A10] (same for arrayB and arrays) and then I want the script to automatically run 10 times (1st one with data A1, B1, C1 / 2nd with A2, B2, C2 etc) with each iteration the data would change to data with n-index from each array.

I'm using selenium and chromedriver

def proxyRotate():
    for i in range(len(proxArr)):
        return proxArr[i]
i = 0
while i < len(proxArr):
    print(proxyRotate())
    i += 1

def get_proxies():
    proxies = ['128.199.254.244:3128', '95.85.79.54:53281', '128.199.125.54:2468', '178.45.8.113:53281', '206.189.225.30:3128']
    return proxies
Lucjan Grzesik
  • 739
  • 5
  • 17
  • So where is the problem? – Olvin Roght May 10 '19 at 00:00
  • Your `proxyRotate()` function will return the first element every time. Rather than looping, fetch the value `i` using an argument to the function. What/Where are your three arrays that you talk about in the question? – razdi May 10 '19 at 00:01
  • There are two other arrays with numbers and i want to pass with every iteration proxy and data from two other arrays later to the main() function – Lucjan Grzesik May 10 '19 at 00:05
  • Is the problem just that you can't rotate through the proxies properly? Or something else? – razdi May 10 '19 at 00:06
  • yes and how do I pass then to the main function with argument? sorry I'm starting with python – Lucjan Grzesik May 10 '19 at 00:06

2 Answers2

2

You can rotate through the proxies without defining a separate function for it. After you make the list, you can just loop over it.

def get_proxies():
    proxies = ['128.199.254.244:3128', '95.85.79.54:53281', '128.199.125.54:2468', '178.45.8.113:53281', '206.189.225.30:3128']
    return proxies

proxArr = get_proxies()

for proxy in proxArr:
    print(proxy)

You can make a call to the required function instead of printing it out.

EDIT

You can use the zip() function to create an iterator over multiple such lists. It will work something like this:


def get_cc(): 
    cc = ['56465465465465', '4654654654654', '54654654654654'] 
    return cc

def get_proxies():
    proxies = ['128.199.254.244:3128', '95.85.79.54:53281', '128.199.125.54:2468', '178.45.8.113:53281', '206.189.225.30:3128']
    return proxies

proxArr = get_proxies()
ccArr = get_cc()

for elem in zip(proxArr, ccArr):
    spotify(elem[0], elem[1])

EDIT 2

Your spotify function should take in 3 elements as well:

def spotify(elem1, elem2, elem3):
    print("proxy: {}, cc: {}, cvc: {}".format(elem1, elem2, elem3))

EDIT 3

If I understand correctly, this should fix your issue. You should take out the re-run logic from the function and into the loop:

import sys

def spotify(elem1, elem2, elem3):

    print("proxy: {}, cc: {}, cvc: {}".format(elem1, elem2, elem3))


def get_cc():
    cc = ['5136154545452522', '51365445452823', '51361265424522']
    return cc

def get_cvc():
    cvc = ['734', '690', '734']
    return cvc

def get_proxies():
    proxies = ['51.77.545.171:8080', '51.77.254.171:8080', '51.77.258.82:8080']
    return proxies

proxArr = get_proxies()
ccArr = get_cc()
cvcArr = get_cvc()
yeslist = ['y','yes']

for elem in zip(proxArr, ccArr, cvcArr):
    spotify(elem[0], elem[1], elem[2])
    restart=input("Do you wish to start again: ").lower()
    if restart not in yeslist:
        sys.exit("Exiting")
razdi
  • 1,388
  • 15
  • 21
  • and if i want to pass data from second array i do it like this? def get_cc(): cc = ['56465465465465', '4654654654654', '54654654654654'] return cc ccArr = get_cc() def get_proxies(): proxies = ['51.77.265.110:8080', '51.77.25.171:8080', '51.77.258.82:8080'] return proxies proxArr = get_proxies() for proxy in proxArr: spotify(proxy, cc) – Lucjan Grzesik May 10 '19 at 00:29
  • The code you wrote works flawlessly but I have no idea how I can pass 2 other values to this for loop the other too must be looped as well as the proxies – Lucjan Grzesik May 10 '19 at 00:36
  • what attribute do i add to my main() function – Lucjan Grzesik May 10 '19 at 01:16
  • I have one more question if you don't mind. Is there a way that I start for example 10 chrome at the same time for each item from array? – Lucjan Grzesik May 10 '19 at 20:05
  • https://stackoverflow.com/questions/56084374/selenium-create-multiple-chrome-threads-for-each-item-in-arraylist-and-execute – Lucjan Grzesik May 10 '19 at 21:14
0
def main(proxArr, ccArr, cvcArr):

    PROXY = proxArr
    creditCard = ccArr
    securityCode = cvcArr



def get_cc():
    cc = ['5136154545452522', '51365445452823', '51361265424522']
    return cc

def get_cvc():
    cvc = ['734', '690', '734']
    return cvc

def get_proxies():
    proxies = ['51.77.545.171:8080', '51.77.254.171:8080', 

'51.77.258.82:8080'] return proxies

proxArr = get_proxies()
ccArr = get_cc()
cvcArr = get_cvc()

for elem in zip(proxArr, ccArr, cvcArr):
    spotify(elem[0], elem[1], elem[2])

I'm doing something wrong cause it passes always the first value I've tried to put elem[0] etc in attribute but it gave me syntax error

edit

I've made it like you've told and It's passing the same value all the time Print is just to see if it's passing the values

def spotify(elem1, elem2, elem3):

    print("proxy: {}, cc: {}, cvc: {}".format(elem1, elem2, elem3))




    PROXY = elem1
    creditCard = elem2
    securityCode = elem3

    restart=input("Do you wish to start again: ").lower()
    if restart in yeslist:
        spotify(elem1, elem2, elem3)
        print("proxy: {}, cc: {}, cvc: {}".format(elem1, elem2, elem3))
    else:
        exit()

def get_cc():
    cc = ['5136154545452522', '51365445452823', '51361265424522']
    return cc

def get_cvc():
    cvc = ['734', '690', '734']
    return cvc

def get_proxies():
    proxies = ['51.77.545.171:8080', '51.77.254.171:8080', '51.77.258.82:8080']
    return proxies

proxArr = get_proxies()
ccArr = get_cc()
cvcArr = get_cvc()

for elem in zip(proxArr, ccArr, cvcArr):
    spotify(elem[0], elem[1], elem[2])
Lucjan Grzesik
  • 739
  • 5
  • 17