配置:適用於Android的Eclipse開發者 - jre1.7 - Windows 8(:s) -在android上的簡單網絡爬蟲?
我正在開發Android上的一個小應用程序。目前,我只想在MainActivity上打印我的網站。我真的試圖用計算器和我的耐心去實現它,我落在下面的源代碼:
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.HashSet;
import java.util.Set;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
public class Crawler {
public static void main(String[] args) throws ClientProtocolException, IOException {
crawlPage("http://www.google.com/");
}
private static void crawlPage(String string) {
// TODO Auto-generated method stub
}
static Set<String checked = new HashSet<String();
@SuppressWarnings("unused") private static void main(String url) throws ClientProtocolException, IOException {
if (checked.contains(url))
return;
checked.add(url);
System.out.println("Crawling: " + url);
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.bratiska.wordpress.com");
HttpResponse response = client.execute(request);
Reader reader = null;
try {
reader = new InputStreamReader(response.getEntity().getContent());
String link="";
new ParserDelegator().parse(reader, link, true);
if (link.startsWith("http://www.libnum.fr"))
crawlPage(link);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
需要幫助的private static void crawlPage()
方法!
這似乎是什麼問題呢? – 2013-03-11 12:38:25
這與Android沒有任何關係 – 2013-03-11 12:40:40
您收到的錯誤是什麼? – kabuto178 2013-03-11 12:43:24