package web_search;
i
mport java.io.BufferedReader;
i
mport java.io.IOException;
i
mport java.io.InputStreamReader;
i
mport java.io.UnsupportedEncodingException;
i
mport java.net.HttpURLConnection;
i
mport java.net.MalformedURLException;
i
mport java.net.URL;
public class HtmlDownloader {
public static void main(String[] args) {
System.out
.println(down("http://www.baidu.com/s?wd=runtime.exec%20%B5%C8%B4%FD%CD%CB%B3%F6&pn=90&tn=monline_4_dg"));
}
public static String down(String u) {
return new Helper().fuck(u);
}
}
class Helper {
public String fuck(String u) {
String[] p = new String[2];
p[0] = u;
p[1] = "";
Thread thread = new T(p);
thread.start();
synchro
nized (this) {
try {
int count = 100;
while (count-- > 0) {
this.wait(100);
if (!thread.isAlive())
break;
}
} catch (Exception e) {
}
if (thread.isAlive())
thread.interrupt();
}
return p[1];
}
}
class T extends Thread {
static String user_agent_str = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0) Gecko/20100101 Firefox/9.0";
String[] l;
public T(String[] p) {
l = p;
}
public void run() {
String fu = l[0];
try {
StringBuilder ret = new StringBuilder();
int HttpResult;
URL url = new URL(fu);
HttpURLCo
nnection urlconn = (HttpURLConnection) url
.openCo
nnection(); // ������
// URLCo
nnection
// ��������ij��࣬����Ӧ�ó����
// URL
// ֮���ͨ�����ӣ�ͨ����
// URL
// �ϵ���
// openCo
nnection
// �����������Ӷ���
//urlconn.addRequestProperty("Accept-Language", "zh-cn");
urlconn.addRequestProperty("User-Agent", user_agent_str);
urlconn.setFollowRedirects(true);
urlconn.setInstanceFollowRedirects(false);
urlconn.co
nnect(); // ʹ�� co
nnect ����������Զ�̶����ʵ������
HttpURLCo
nnection httpconn = (HttpURLConnection) urlconn; // ÿ��
// HttpURLCo
nnection
// ʵ���������ɵ������