假设你用的 java 写的爬虫,那么设置代理然后爬就是这样的
``` java
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ProxySelector;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
var httpClient = HttpClient.newBuilder().proxy(ProxySelector.of(new InetSocketAddress("localhost", 8080))).build();
var requesrt = HttpRequest.newBuilder(URI.create("
https://baidu.com")).build();
var response = httpClient.send(requesrt, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
```