在我的python脚本中,我输入了3条数据,分别称为A,B,C。 我想在数组中输入数据,例如,arrayA = [A1,A2 ... A10](与arrayB和数组相同),然后我希望脚本自动运行10次(第一个使用数据A1,B1, C1 / 2nd与A2,B2,C2等),每次迭代时,数据将从每个数组变为具有n-index的数据。
我正在使用硒和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
答案 0 :(得分: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
proxArr = get_proxies()
for proxy in proxArr:
print(proxy)
您可以调用所需的功能,而不必将其打印出来。
编辑
您可以使用zip()函数在多个此类列表上创建迭代器。它将像这样工作:
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])
编辑2
您的Spotify函数也应包含3个元素:
def spotify(elem1, elem2, elem3):
print("proxy: {}, cc: {}, cvc: {}".format(elem1, elem2, elem3))
编辑3
如果我正确理解,这应该可以解决您的问题。您应该从函数中取出重新运行逻辑并进入循环:
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")
答案 1 :(得分:0)
function click1() is changed to function click2()
'51 .77.258.82:8080'] 返回代理
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',
我做错了,因为它总是传递我尝试放入elem [0]等的第一个值 属性,但它给了我语法错误
编辑
我做到了,就像您说的那样,并且始终传递相同的值 打印只是看它是否传递值
proxArr = get_proxies()
ccArr = get_cc()
cvcArr = get_cvc()
for elem in zip(proxArr, ccArr, cvcArr):
spotify(elem[0], elem[1], elem[2])