2013-10-09 29 views
0

我正在嘗試編寫一個代碼來抓取網站並使用httpclient。我正在嘗試導入適當的類來運行我的程序,但它說包不存在。我已經看過他們的API,試圖找出它,但仍然不能。我的代碼是:如何在Java博士中導入HTTPClient?

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()); 
     } 
    } 
    } 
} 
+0

你下載JAR文件,並把它們放在classpath?這可能也是讓你熟悉Maven的好時機......它讓我的生活變得更加輕鬆...... – ppeterka

+0

我會研究Maven。我沒有將JAR添加到類路徑中。我會怎麼做呢? – cmart

+0

[本文](http://www.seas.upenn.edu/~cis1xx/resources/java/jar/jarindrjava.html)描述了DRJava – ppeterka

回答

0

嘗試:org.apache.http.client.HttpClient