So I found a proxy checker I wanted to edit it to where I could delete faulty proxies if they didn't work from my textfile, but I have it select a random line from my textfile so I don't know how to delete it. I was thinking maybe searching for the proxy in the file and then deleting the line its on but have no idea how to do that?
PHP Code
<?php
def is_bad_proxy(pip):
try:
proxy_handler = urllib2.ProxyHandler({'http': pip})
opener = urllib2.build_opener(proxy_handler)
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib2.install_opener(opener)
req=urllib2.Request('http://whatismyipaddress.com/')
sock=urllib2.urlopen(req)
except urllib2.HTTPError, e:
print 'Error code: ', e.code
return e.code
except Exception, detail:
print "ERROR:", detail
return True
return False
def main():
socket.setdefaulttimeout(120)
proxyList = [random.choice(open('proxies.txt', 'r').readlines())]
for currentProxy in proxyList:
if is_bad_proxy(currentProxy):
print "Bad Proxy %s" % (currentProxy)
#where i need to put the code where I delete the proxy
main()
else:
print "%s is working" % (currentProxy)
global currentProxy

