Search code examples
pythonrandomproxytwistedweb

Python, Twisted, Proxy and rotating the proxy server


I use the below to starting the reactor for fetching web pages... So...all pages I fetch use the proxy once the reactor starts. But...what if I want to rotate proxies? How do I do that using e.g. random.choice(proxy_list)

Thanks

site = server.Site(proxy.ReverseProxyResource('173.000.342.234', 8800, ''))
reactor.listenTCP(8080, site)
reactor.run()

Solution

  • Take a look at the implementation. Notice where it uses the supplied IP and port to set up a new connection with reactor.connectTCP. Subclass ReverseProxyResource and extend it to be able to connect to your randomly selected address.