sorry if my english is not good.
I wanna write a program that can open the site every 15 seconds. But do it with a different IP. That means get a list of IP and every 15 seconds open a website. How did you do it? What module should I use? Thanks you
sorry if my english is not good. I wanna write a program that can
Share
If you’re asking how to make sure you fire off one connection every 15 seconds, even though it may take a few seconds (maybe even longer than 15) for each one, that’s easy. Since you’re only making one connection every 15 seconds, there’s really no reason not to just spawn a thread for each one.
So:
If you’re talking about destination IPs, and you want to know how to use a different one for each request… well, you usually just modify the URL. Something like this:
If you’re asking how to bind a source address with your chosen URL-downloading library, you’d have to tell us which library, but: Either the library will have a parameter for it, or it will have a way for you to specify a
socketfactory, or it will be impossible (unless you want to monkeypatchsocket.socketwith your own factory). If it lets you specify asocketfactory, the way to do it is this:Then just pass in
make_socket_factory(srcip)as the factory.If you want to know how to download a URL in the first place… there are a lot of ways to do that, from the stdlib
urllib2torequestsandpycurltotwisted, and there are already plenty of answers on SO (and elsewhere) comparing and contrasting them.