Giter Site home page Giter Site logo

test's Introduction

Test

Ryan K K Lam Testing project

test's People

Contributors

ryankklam avatar

Watchers

 avatar

test's Issues

muti-thread dowload

线程并行下载的核心特点就是分段,并行下载。
比如一个文件200M,分5个线程,那么就给砍成5份,分别同时下就好了。速度当然比一点点下载来的要快的多。

package com.javaer.examples.file;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class MyMutilDown {
/**
* 单线程的远程下载
*/
public void SingleDown(String filePath, String url) {
try {
// 要写入的文件
File file = new File(filePath + getFileExtName(url));
FileWriter fWriter = new FileWriter(file);
URL ul = new URL(url);
URLConnection conn = ul.openConnection();
conn.setConnectTimeout(2000);// 请求超时时间
// int len = conn.getContentLength();
InputStream in = conn.getInputStream();
// byte[] by = new byte[1024];
int temp = 0;
while ((temp = in.read()) != -1) {
System.out.println(temp);
fWriter.write(temp);
}
fWriter.close();
in.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

/**
 * 文件后缀名
 * 
 * @param path
 * @return
 */
public String getFileExtName(String path) {
    return path.substring(path.lastIndexOf("."));
}

/**
 * 测试多线程
 * 
 * @param filePath
 *            文件保存路径
 * @param url
 *            url
 * @param tnum
 *            线程数量
 */
public void MutiDown(String filePath, String url, int tnum) {
    try {
        // 要写入的文件
        final File file = new File(filePath + getFileExtName(url));
        System.out.println(file.getAbsolutePath());
        RandomAccessFile accessFile = new RandomAccessFile(file, "rwd");// 建立随机访问
        final URL ul = new URL(url);
        HttpURLConnection conn = (HttpURLConnection) ul.openConnection();
        conn.setConnectTimeout(2000);// 请求超时时间
        conn.setRequestMethod("GET");
        int len = conn.getContentLength();// 文件长度
        accessFile.setLength(len);
        accessFile.close();
        final int block = (len + tnum - 1) / tnum;// 每个线程下载的快大小

        for (int i = 0; i < tnum; i++) {
            final int a = i;
            new Thread(new Runnable() {
                int start = block * a;// 开始位置
                int end = block * (a + 1) - 1;// 结束位置

                @Override
                public void run() {
                    HttpURLConnection conn2 = null;
                    RandomAccessFile accessFile2 = null;
                    InputStream in = null;
                    try {
                        conn2 = (HttpURLConnection) ul.openConnection();
                        conn2.setConnectTimeout(2000);// 请求超时时间
                        conn2.setRequestMethod("GET");
                        // TODO Auto-generated method stub
                        conn2.setRequestProperty("Range", "bytes=" + start
                                + "-" + end + "");// 设置一般请求属性 范围
                        in = conn2.getInputStream();
                        byte[] data = new byte[1024];
                        int len = 0;
                        accessFile2 = new RandomAccessFile(file, "rwd");
                        accessFile2.seek(start);

                        while ((len = in.read(data)) != -1) {
                            System.out.println(a + "/" + len);
                            accessFile2.write(data, 0, len);//并发写入
                        }
                        System.out.println("线程:" + a + "下载完成!");
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } finally {
                        try {
                            accessFile2.close();
                            in.close();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                    }
                }
            }).start();

        }

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

/**
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    MyMutilDown mydown = new MyMutilDown();
    String path = "http://s2.knowsky.com/code/php/openx-220080603.rar";
    // mydown.SingleDown("/", path);
    mydown.MutiDown("/bbc", path, 3);
}

}

Cardio followup

<script>

String.prototype.temp = function(obj) {
    return this.replace(/\$\w+\$/gi, function(matchs) {
        var returns = obj[matchs.replace(/\$/g, "")];
        return (returns + "") == "undefined"? "": returns;
    });
};


$(document).ready(function(){

            // <div class="col-md-4">
            //  <div class="intro-table intro-table-hover">
            //      <h5 class="white heading hide-hover">Premium Membership</h5>
            //      <div class="bottom">
            //          <h4 class="white heading small-heading no-margin regular">Register Today</h4>
            //          <h4 class="white heading small-pt">20% Discount</h4>
            //          <a href="#" class="btn btn-white-fill expand">Register</a>
            //      </div>
            //  </div>
            // </div>

// "bs-example-navbar-collapse-1"
// alert($("#bs-example-navbar-collapse-1").html());

    var test1=$("<div></div>");   // 以 jQuery 创建新元素
    test1.attr("class", "col-md-4");

    var test2=$("<div></div>");  
    test2.attr("class", "intro-table intro-table-hover");


    // var header5=$("<h5 class='white heading hide-hover'>Test Membership</h5>");
    var test3 = $("<h5 class='white heading hide-hover'>Advance Membership</h5><div class='bottom'><h4 class='white heading small-heading no-margin regular'>Register Today</h4><h4 class='white heading small-pt'>100% Off!!!</h4><a href='#' class='btn btn-white-fill expand'>Register</a></div>");
        // <div class="bottom">
        // <h4 class="white heading small-heading no-margin regular">Register Today</h4>
        // <h4 class="white heading small-pt">20% Discount</h4>
        // <a href="#" class="btn btn-white-fill expand">Register</a>
        // </div>");

    // test3 = header5.append(test3);
    test2.html(test3);
    test1.html(test2);
    // alert(test1.html());

    // $("#happyclient").after(test1);
    $(".row.intro-tables").append(test1);


var courtList = {
    typeId: "court",
    courtDetails: [{ id: "000010", name: "广东药学院宝岗校区", address: "宝岗光汉直街40号.", description: "老城中心", picture: "./img/1.png"},
        { id: "000011", name: "第一染织厂足球场", address: "海珠区新港中路489号区(近佳信花园).", description: "场地标准", picture: "./img/3.png" },
        { id: "000012", name: "江南新村第一小学", address: "紫龙大街8号.", description: "地铁上盖", picture: "./img/5.png" }]
};

var courtMainDiv =$("<div class='col-md-4'><div id='$id$' class='intro-table intro-table-hover'><h5 class='white heading hide-hover'>$description$</h5><div class='bottom'><h4 class='white heading small-heading no-margin regular'>$name$</h4><h4 class='white heading small-pt'>$address$</h4><a href='#' class='btn btn-white-fill expand'>详情</a></div></div></div>");
var courtContainerDiv = courtMainDiv.html();

courtList.courtDetails.forEach(function(obj){
    var courtBox = courtMainDiv.html(courtContainerDiv.temp(obj));
    $(".row.intro-tables").append(courtBox.clone());

    var divTemp = "div#" + obj.id;
    var picUrl = "url(" + obj.picture + ")";
    alert(picUrl)

; $(divTemp).css("background-image",picUrl);
// $("div#").css("backgroundImage","url(imgs/right.png)");
})

    });
</script>

Sync LoginHuoChe

package com.yung.ticket;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.commons.httpclient.Cookie;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.NTCredentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.params.ConnRouteParams;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LoginHuoche {
private static Logger log = LoggerFactory.getLogger(LoginHuoche.class);
private Cookie[] cookies;
private String cookiestr;
public boolean isLogin = false;
private String token;
private static String code = "";
private HttpClient httpclient = WebClientDevWrapper.wrapClient(new DefaultHttpClient());
// private HttpClient httpclient = new DefaultHttpClient();

/**
 * 发送登录信息,记录cookie,登录状态,token等信息
 * 
 * @return
 */
private boolean _login_12306() {
    log.debug("-----------------login start-----------------------");
    HttpPost httppost = new HttpPost(
            "https://kyfw.12306.cn/otn/login/loginAysnSuggest");
    List<NameValuePair> parameters = new ArrayList<NameValuePair>();
    // parameters.add(new BasicNameValuePair("method", "login"));
    parameters.add(new BasicNameValuePair("loginUserDTO.user_name",
            "davayunhuijia"));
    parameters
            .add(new BasicNameValuePair("userDTO.password", "a123456789"));
    parameters.add(new BasicNameValuePair("randCode", code));
    String responseBody = null;
    try {
        UrlEncodedFormEntity uef = new UrlEncodedFormEntity(parameters,
                HTTP.UTF_8);
        httppost.setEntity(uef);
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        responseBody = httpclient.execute(httppost, responseHandler);
        System.out.println(responseBody);
    } catch (Exception e) {
        e.printStackTrace();
    }
    /*
     * try { PostMethod post = new
     * PostMethod("https://kyfw.12306.cn/otn/login/loginAysnSuggest");
     * post.setRequestHeader("Referer",
     * " https://kyfw.12306.cn/otn/login/init");
     * post.setRequestHeader(Weixin.USER_AGENT_H, Weixin.USER_AGENT);
     * NameValuePair[] params = new NameValuePair[] {new
     * NameValuePair("loginUserDTO.user_name", "davayunhuijia"), new
     * NameValuePair("userDTO.password", "a123456789"), new
     * NameValuePair("randCode", "aaa")}; post.setQueryString(params); int
     * status = client.executeMethod(post); String ret =
     * post.getResponseBodyAsString(); System.out.println("ret:" + ret); }
     * catch (Exception e) { String info = "【12306登陆】【发生异常:" +
     * e.getMessage() + "】"; System.err.println(info); log.warn(info);
     * return false; }
     */
    return false;
}

//
/**
 * 发送登录信息,记录cookie,登录状态,token等信息
 * 
 * @return
 */
private boolean login_elong() {
    log.debug("-----------------login start-----------------------");
    HttpPost httppost = new HttpPost(
            "https://secure.elong.com/passport/isajax/Login/LoginAgent");
    List<NameValuePair> parameters = new ArrayList<NameValuePair>();
    // parameters.add(new BasicNameValuePair("method", "login"));
    parameters.add(new BasicNameValuePair("actiondo","login"));
    parameters.add(new BasicNameValuePair("loginname", "ryan4299899%40126.com"));
    parameters.add(new BasicNameValuePair("pwd", "123456"));
    parameters.add(new BasicNameValuePair("vcode", ""));
    parameters.add(new BasicNameValuePair("cardno", ""));
    parameters.add(new BasicNameValuePair("isRememberMe", "false"));
    parameters.add(new BasicNameValuePair("language", "cn"));
    parameters.add(new BasicNameValuePair("viewpath", "~%2Fviews%2Fmyelong%2Fpassport%2Flogin.aspx"));

    String responseBody = null;
    try {
        UrlEncodedFormEntity uef = new UrlEncodedFormEntity(parameters,
                HTTP.UTF_8);
        httppost.setEntity(uef);
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        responseBody = httpclient.execute(httppost, responseHandler);
        System.out.println(responseBody);
    } catch (Exception e) {
        e.printStackTrace();
    }
    /*
     * try { PostMethod post = new
     * PostMethod("https://kyfw.12306.cn/otn/login/loginAysnSuggest");
     * post.setRequestHeader("Referer",
     * " https://kyfw.12306.cn/otn/login/init");
     * post.setRequestHeader(Weixin.USER_AGENT_H, Weixin.USER_AGENT);
     * NameValuePair[] params = new NameValuePair[] {new
     * NameValuePair("loginUserDTO.user_name", "davayunhuijia"), new
     * NameValuePair("userDTO.password", "a123456789"), new
     * NameValuePair("randCode", "aaa")}; post.setQueryString(params); int
     * status = client.executeMethod(post); String ret =
     * post.getResponseBodyAsString(); System.out.println("ret:" + ret); }
     * catch (Exception e) { String info = "【12306登陆】【发生异常:" +
     * e.getMessage() + "】"; System.err.println(info); log.warn(info);
     * return false; }
     */
    return false;
}

// 获取旅客信息
public byte[] getElongJsonp() {
    HttpGet get = new HttpGet("http://hotel.elong.com/hotcitycms/true.html?callback=jsonp14181148382");

// HttpGet get = new HttpGet("https://dap004a.hk.hsbc:30143/");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        HttpResponse response = httpclient.execute(get);
        System.out.println(response.toString());
        Header[] hs = response.getAllHeaders();
        for (Header header : hs) {
            System.out.println(header.getName() + " " + header.getValue());
            if (header.getName().equals("Set-Cookie")) {
                cookiestr += header.getValue() + ";";
            }
        }
        HttpEntity entity = response.getEntity();
        // log.debug(response.getStatusLine());
        if (entity != null) {
            InputStream is = entity.getContent();
            byte[] buf = new byte[1024];
            int len = -1;
            while ((len = is.read(buf)) > -1) {
                baos.write(buf, 0, len);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        log.error("获取验证码失败");
    }
    return baos.toByteArray();
}
// 、https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew.do?module=login&rand=sjrand&0.5852866363711655
// 获取验证码
public byte[] getImage() {
    HttpGet get = new HttpGet(
            "https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew.do?module=login&rand=sjrand&0.5852866363711655");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        HttpResponse response = httpclient.execute(get);
        System.out.println(response.toString());
        Header[] hs = response.getAllHeaders();
        for (Header header : hs) {
            System.out.println(header.getName() + " " + header.getValue());
            if (header.getName().equals("Set-Cookie")) {
                cookiestr += header.getValue() + ";";
            }
        }
        HttpEntity entity = response.getEntity();
        // log.debug(response.getStatusLine());
        if (entity != null) {
            InputStream is = entity.getContent();
            byte[] buf = new byte[1024];
            int len = -1;
            while ((len = is.read(buf)) > -1) {
                baos.write(buf, 0, len);
            }
        }
    } catch (Exception e) {
        log.error("获取验证码失败");
    }
    return baos.toByteArray();
}

private boolean checkImage() {
    HttpPost httppost = new HttpPost(
            "https://kyfw.12306.cn/otn/passcodeNew/checkRandCodeAnsyn");
    httppost.setHeader("Cookie", cookiestr);
    List<NameValuePair> parameters = new ArrayList<NameValuePair>();
    // parameters.add(new BasicNameValuePair("method", "login"));
    parameters.add(new BasicNameValuePair("randCode", code));
    parameters.add(new BasicNameValuePair("rand", "sjrand"));
    String responseBody = null;
    try {
        UrlEncodedFormEntity uef = new UrlEncodedFormEntity(parameters,
                HTTP.UTF_8);
        httppost.setEntity(uef);
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        responseBody = httpclient.execute(httppost, responseHandler);
        System.out.println(responseBody);
    } catch (Exception e) {
        e.printStackTrace();
    }
    /*
     * try { PostMethod post = new
     * PostMethod("https://kyfw.12306.cn/otn/login/loginAysnSuggest");
     * post.setRequestHeader("Referer",
     * " https://kyfw.12306.cn/otn/login/init");
     * post.setRequestHeader(Weixin.USER_AGENT_H, Weixin.USER_AGENT);
     * NameValuePair[] params = new NameValuePair[] {new
     * NameValuePair("loginUserDTO.user_name", "davayunhuijia"), new
     * NameValuePair("userDTO.password", "a123456789"), new
     * NameValuePair("randCode", "aaa")}; post.setQueryString(params); int
     * status = client.executeMethod(post); String ret =
     * post.getResponseBodyAsString(); System.out.println("ret:" + ret); }
     * catch (Exception e) { String info = "【12306登陆】【发生异常:" +
     * e.getMessage() + "】"; System.err.println(info); log.warn(info);
     * return false; }
     */
    return false;
}

public byte[] findCheci() {
    System.out.println("findcheci");
    HttpGet get = new HttpGet(
            "https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date=2014-03-18&leftTicketDTO.from_station=SZQ&leftTicketDTO.to_station=WHN&purpose_codes=ADULT");
    get.setHeader("Cookie", cookiestr);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        HttpResponse response = httpclient.execute(get);
        System.out.println(response.toString());
        System.out.println("findcheci2");
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream is = entity.getContent();
            byte[] buf = new byte[1024];
            int len = -1;
            while ((len = is.read(buf)) > -1) {
                baos.write(buf, 0, len);
            }
        }
    } catch (Exception e) {
        log.error("获取验证码失败");
    }
    return baos.toByteArray();
}

// checkUser
// submitOrderRequest
public void submitOrderRequest() {
    // https://kyfw.12306.cn/otn/leftTicket/submitOrderRequest post
    String secretStr;
    String train_date;// :2014-03-08
    String back_train_date;// :2014-03-06
    String tour_flag;// :dc
    String purpose_codes;// :ADULT
    String query_from_station_name;// :深圳
    String query_to_station_name;// :武汉
    String undefined;// :
}

// 获取旅客信息
public byte[] getPassengerDTOs() {
    // https://kyfw.12306.cn/otn/confirmPassenger/getPassengerDTOs get
    System.out.println("findcheci");
    HttpGet get = new HttpGet(
            "https://kyfw.12306.cn/otn/confirmPassenger/getPassengerDTOs");
    get.setHeader("Cookie", cookiestr);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        HttpResponse response = httpclient.execute(get);
        System.out.println(response.toString());
        System.out.println("findcheci2");
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream is = entity.getContent();
            byte[] buf = new byte[1024];
            int len = -1;
            while ((len = is.read(buf)) > -1) {
                baos.write(buf, 0, len);
            }
        }
    } catch (Exception e) {
        log.error("获取验证码失败");
    }
    return baos.toByteArray();
}

public static void main(String[] args) throws IOException {
    LoginHuoche l = new LoginHuoche();

// //设置代理服务器的ip地址和端口
// String proxyHost = "intpxy1.hk.hsbc";
// int proxyPort = 8080;
//
// //set user id/pwd
// String userName = "43415546";
// String password = "Dounoilu200409$";
//
//// HttpClient httpClient = new HttpClient();
// DefaultHttpClient httpClient = new DefaultHttpClient();
// httpClient.getCredentialsProvider().setCredentials(
// new AuthScope(proxyHost, proxyPort),
// new UsernamePasswordCredentials(userName, password));

// l.httpclient.getParams().setParameter(arg0, arg1)

// l.httpclient.getParams().setParameter(CredentialsParams, password);
// setCredentials(
// new AuthScope(proxyHost, proxyPort),
// new UsernamePasswordCredentials(userName, password));

//
// HttpHost proxy = new HttpHost(proxyHost,proxyPort);
// l.httpclient.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);

    l.getElongJsonp();// testing method
    l.login_elong(); // testing method
    byte[] b = l.getImage();
    File f = new File("C:/a.jpg");
    FileOutputStream fos = new FileOutputStream(f);
    fos.write(b);
    fos.close();
    Scanner s = new Scanner(System.in);
    System.out.println("code:");
    String name = s.nextLine();
    code = name;
    l.checkImage();
    l._login_12306();
    // 查询---车次列表
    /*
     * byte[] bs = l.findCheci(); String str = new String(bs); QueryBaseJson
     * queryBaseJson = JSON.parseObject(str, QueryBaseJson.class);
     * System.out.println(queryBaseJson.getValidateMessagesShowId());
     */
    // 查询添加的乘客信息
    byte[] bp = l.getPassengerDTOs();
    System.out.println(new String(bp));
}

}

//避免HttpClient的”javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated”异常
//TrustManager是一个检查给定的证书是否有效的类。
//SSL使用的模式是X.509(http://en.wikipedia.org/wiki/X.509),对于该模式Java有一个特定的TrustManager,称为X509TrustManager。
class WebClientDevWrapper {
public static HttpClient wrapClient(HttpClient base) {
try {

        //首先我们需要得到一个SSLContext
        //TLS是SSL的继承者,但是它们使用相同的SSLContext。
        SSLContext ctx = SSLContext.getInstance("TLS");
        X509TrustManager tm = new X509TrustManager() {
            @Override
            public void checkClientTrusted(X509Certificate[] arg0,
                    String arg1) throws CertificateException {
            }

            //其实就是这里override掉checkServerTrusted method,不去check证书
            @Override
            public void checkServerTrusted(X509Certificate[] arg0,
                    String arg1) throws CertificateException {
            }

            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }

        };

        ctx.init(null, new TrustManager[] { tm }, null);

        //最后我们创建SSLSocketFactory
        SSLSocketFactory ssf = new SSLSocketFactory(ctx,
                SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        ClientConnectionManager ccm = base.getConnectionManager();

        //现在我们仍然需要将SSLSocketFactory注册到我们的HttpClient上。这是在SchemeRegistry中完成的
        SchemeRegistry sr = ccm.getSchemeRegistry(); 

        //我们注册了一个新的Scheme,使用协议https,我们新创建的SSLSocketFactory包含了我们的TrustManager,然后我们告诉HttpClienthttps的默认端口是443.
        sr.register(new Scheme("https", 443, ssf));


        //设置代理服务器的ip地址和端口  
        String proxyHost = "intpxy1.hk.hsbc";
        int proxyPort = 8080;

        //set user id/pwd
        String userName = "HBAP\\43415546";
         String password = "Dounoilu200409$";

// HttpClient httpClient = new HttpClient();
DefaultHttpClient httpClient = new DefaultHttpClient(ccm, base.getParams());
httpClient.getCredentialsProvider().setCredentials(
new AuthScope(proxyHost, proxyPort),
// new UsernamePasswordCredentials(userName, password));
new NTCredentials(userName, password,"","intpxy1.hk.hsbc"));

         HttpHost proxy = new HttpHost(proxyHost,proxyPort);
         httpClient.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);

         return httpClient;

// return new DefaultHttpClient(ccm, base.getParams());

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

}

enquiryDocInfo

public void test_Joup() throws IOException{

    File pages = new File(".\\Pages\\QuickSearch.htm"); //相对路径
    Document docPages = Jsoup.parse(pages, "UTF-8", "www.guahao.gov.cn");

// Element docBasicInfo = (Element) docPages.select("div.resultList").first();
Element docBasicInfo = (Element) docPages.select("ul.bg_kk li").first(); //li element under ul class = "bg_kk"
Element link = docBasicInfo.select("a[href]").first();
String linkHref = link.attr("href");
String linkText = link.text();
String linkText2 = docBasicInfo.text();
java.net.URLDecoder.decode(linkText, "UTF-8");

    Pattern pt = Pattern.compile("DOC_ID=([\\d]+)"); //匹配以字符串“DOC_ID=”开头,后面匹配数字 
    Matcher mt = pt.matcher(linkHref);
    if(mt.find()) {
        String matcher = mt.group(0);
        String docID = mt.group(1);

// expertID = matcher.substring(matcher.lastIndexOf("/")+1, matcher.lastIndexOf("?")); //截取/开头 , 问号结束中间的字符串
System.out.println(docID);
System.out.println(linkText);
}

// this.getVar("DOC_ID", linkHref, "0");
System.out.println("End.");
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.