如何在Java博士中导入HTTPClient?

时间:2013-10-09 20:16:17

标签: java apache-httpclient-4.x

我正在尝试编写代码来抓取网站并使用httpclient。我试图导入适当的类来运行我的程序,但它说该包不存在。我看过他们的API试图弄明白但仍然不能。我的代码是:

import java.io.IOException; 
import org.apache.commons.httpclient.*; 
import org.apache.commons.httpclient.methods.*;
import java.util.Scanner  

public class Scraper3 { 

  public static String scrapeWebsite() throws IOException {

HttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet("http://ichart.finance.yahoo.com/table.csv?s=MSFT");
    HttpResponse response = client.execute(get);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        Scanner scanner = new Scanner(entity.getContent());
        while (scanner.hasNextLine()) {
            System.out.println(scanner.nextLine());
        }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

尝试:org.apache.http.client.HttpClient