我在一个AWS托管服务器上运行一些web爬行作业。爬虫从eCommerce网站抓取数据,但最近爬虫从网站中获得“超时错误”。根据我的IP地址,该网站可能限制了我的访问频率。分配一个新的弹性IP地址可以解决这个问题,但不会持续很长时间。
我的问题是:我是否可以使用任何服务来自动和动态地分配和关联新的IP到我的实例?谢谢!
发布于 2014-04-08 19:47:02
要更改EIP,只需使用Python即可。
就像这样:
#!/usr/bin/python
import boto.ec2
conn = boto.ec2.connect_to_region("us-east-1",
aws_access_key_id='<key>',
aws_secret_access_key='<secret>')
reservations = ec2_conn.get_all_instances(filters={'instance-id' : 'i-xxxxxxxx'})
instance = reservations[0].instances[0]
old_address = instance.ip_address
new_address = conn.allocate_address().public_ip
conn.disassociate_address(old_address)
conn.associate_address('i-xxxxxxxx', new_address)发布于 2014-04-08 20:22:10
如果要使用TOR网络,只需执行:
sudo apt-get install tor
sudo /etc/init.d/tor start
netstat -ant | grep 9050 # Tor port在您的java项目中,您将代理设置为:
public static void main(String[] args) {
System.setProperty("socksProxyHost", "127.0.0.1");
System.setProperty("socksProxyPort", "9050");您可以调度每次XX次重新启动应用程序和tor的cron作业。
简单又安全。
https://stackoverflow.com/questions/22942812
复制相似问题