今天在找Java的爬虫的库,发现Java的爬虫框架挺多的,常见的有nutch,Heritrix,crawler4j等。
但我想要的是类似Python的requests库的Java库。
看到一个库叫Unirest,但是我尝试后发现并不好用,而且这个库的最后更新时间是16年。
最后我选择了HttpComponents ,里面包含的组件有 HttpClient, HttpAsyncClient 。
在Maven中添加如下依赖:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.8</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient