I open the file as follows:

with open(proxy_file) as proxy: ips = [row.rstrip() for row in proxy] 

If I remember correctly, all data is stored as follows:

 ['1.2.3.4:80', '1.2.3.4:3128', '1.2.3.4:8080'] 

And so on. Can I somehow do an alternate search of these addresses? And then I have so far only succeeded in making a random selection from the list.

 index = random.randint(0,len(ips)-1) proxies = {'http': ips[index]} 
  • Can. Take advantage of the cycle. - Sergey Gornostaev

2 answers 2

Use the for ... in construct

For example:

 for ip in ips: print('Ещё один айпишник - ' + str(ip)) 

Read more here: http://pythontutor.ru/lessons/for_loop/

     def get(proxy_file): yield from (row.rstrip() for row in open(proxy_file)) for row in get('file'): print(row)