查询腾讯招聘结果的代码,告别繁琐的打开微信查看。(纯属无聊)

更简单的有curl操作,还有python里的库,这个是JAVA版本,纯属无聊,喜欢的人看看就行。

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
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.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpParams;
/**
*
*/
/**
 * @author Iver3oN Zhang
 * @date 2016年4月26日
 * @email grepzwb@qq.com Query.java Impossible is nothing
 */
public class Query {
  /**
   * @param args
   */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    // httpClientGet();
    httpClientPost();
  }
  // HttpClient 的POST方式
  public static void httpClientPost() {
    String urlAddress = "http://m.join.qq.com/query/result";
    HttpPost httpPost = new HttpPost(urlAddress);
    List paras = new ArrayList<>();
    NameValuePair pair1 = new BasicNameValuePair("type", "query_result");
    NameValuePair pair2 = new BasicNameValuePair("idcard", "267*");
    NameValuePair pair3 = new BasicNameValuePair("phone", "1832968****");
    paras.add(pair1);
    paras.add(pair2);
    paras.add(pair3);
    try {
      HttpEntity entity = new UrlEncodedFormEntity(paras, "gbk");
      httpPost.setEntity(entity);
      HttpClient client = new DefaultHttpClient();
      try {
        HttpResponse ht = client.execute(httpPost);
        // 连接成功
        if (ht.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
          HttpEntity het = ht.getEntity();
          InputStream is = het.getContent();
          BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
          String response = "";
          String readLine = null;
          while ((readLine = br.readLine()) != null) {
            // response = br.readLine();
            response = response + readLine;
          }
          is.close();
          br.close();
          // String str = EntityUtils.toString(he);
          // System.out.println("=========&&" + response);
          int i = response.indexOf("<p>");
          int j = response.lastIndexOf("</p>");
          System.out.println(response.substring(i, j).trim());
        } else {
        }
      } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  // httpClient 方式发送get请求
  // 由于腾讯校招微信官网查看源代码 是通过post方式请求的,其实也必须是post方式。。。这个方式暂时不用
  public static void httpClientGet() {
    System.out.println("--------------");
    String urlAddress = "http://m.join.qq.com/query/result";
    String type = "query_result";
    // your id back 4
    String idcard = "267*";
    // your phonenumber
    String phone = "1832968****";
    String getUrl = urlAddress + "?type=" + type + "&idcard=" + idcard + "&phone=" + phone;
    HttpGet httpGet = new HttpGet(getUrl);
    HttpParams hp = httpGet.getParams();
    hp.getParameter("true");
    httpGet.setHeader("Referer", "http://m.join.qq.com/school/index");
    // hp.
    // httpGet.setp
    HttpClient hc = new DefaultHttpClient();
    try {
      HttpResponse ht = hc.execute(httpGet);
      System.out.println("xaxaxa");
      System.out.println(ht.getStatusLine().getStatusCode());
      if (ht.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        System.out.println("OK");
        HttpEntity he = ht.getEntity();
        InputStream is = he.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        String response = "";
        String readLine = null;
        while ((readLine = br.readLine()) != null) {
          // response = br.readLine();
          response = response + readLine;
        }
        is.close();
        br.close();
        // String str = EntityUtils.toString(he);
        System.out.println("=========" + response);
      } else {
      }
    } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}


全部评论
😂讲道理应该有两个textview输入信息,一个提交一个清除数据吧,本地存一下查询信息,不然帮别人查还得修改代码。。。。非挑刺,只是小小的意见,见谅
点赞 回复 分享
发布于 2016-05-13 22:40
当初面试写的Android版,http://git.oschina.net/XuChunH/TencentInterviewQuery,可惜没如果
点赞 回复 分享
发布于 2016-05-12 16:50
可惜我已经用不着了
点赞 回复 分享
发布于 2016-05-12 15:37

相关推荐

马上要带我人生中的第一个实习生了,想问问大家都喜欢什么的mentor?好让我有个努力的目标
拒绝996的劳伦斯很勇敢:看得见目标且护犊子的 具体就是明确告诉组员要干什么,然后当别的组甩dirty work时能护的组自家新人
点赞 评论 收藏
分享
野猪不是猪🐗:现在的环境就是这样,供远大于求。 以前卡学历,现在最高学历不够卡了,还要卡第一学历。 还是不够筛,于是还要求得有实习、不能有gap等等... 可能这个岗位总共就一个hc,筛到最后还是有十几个人满足这些要求。他们都非常优秀,各方面都很棒。 那没办法了,看那个顺眼选哪个呗。 很残酷,也很现实
点赞 评论 收藏
分享
04-02 16:49
门头沟学院 Java
_bloodstream_:我也面了科大讯飞,主管面的时候听说急招人优先考虑能尽快实习的,我说忙毕设,后面就一直没消息了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务