Reputation: 27
I bought a proxy service which gives me an API that when opened, shows what seems like a big text file of stacked proxies like this, example:
39.134.10.2:8080
139.59.2.223:8888
39.134.10.250:8080
61.5.207.102:80
39.134.146.130:8088
60.194.46.119:3128
161.139.222.254:9000
39.134.10.21:8080
148.217.94.54:3128
60.194.46.118:3128
39.134.10.28:8080
39.134.10.250:90
200.255.122.174:8080
219.239.142.253:3128
118.190.210.227:3128
I want to make it an updating dictionary in python 2.7. Most of what i've seen is people either webscraping proxies or using json to get them. My API link gets an error:
ValueError: No JSON object could be decoded
I just need to send the ip(s) to a dictionary in Python which then I can make selenium use.
I tried to do this:
import urllib2, json
ipadd = urllib.urlop('link to API')
json.load(ipadd)
I could always copy-paste the ip(s) to a notepad every 24 hours but that defeats the purpose of the API and I'm sure it's something easy that I don't see. I'm new to network programming. Thank you
Upvotes: 2
Views: 49
Reputation: 1290
You could try with this:
import requests
url = 'your_API_url'
ips = requests.get(url).text
for ip in ips.splitlines():
# process each ip and port
Upvotes: 2