package com.taurus;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class CjolActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private static final String LOGON_SITE = "http://www.cjol.com";
private static final String USERNAME = "*****";
private static final String PASSWORD = "****";
private static final int LOGON_PORT = 80;
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnCheck = (Button) findViewById(R.id.btnCheck);
tv = (TextView) findViewById(R.id.textView);
btnCheck.setOnClickListener(this);
try {
main();
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void main() throws HttpException, IOException{
StringBuffer sb = new StringBuffer();
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);
// 设置代理对象 ip/代理名称,端口
// client.getHostConfiguration().setProxy("localhost", 8888);
// 登录页面
PostMethod post = new PostMethod(
"http://www.cjol.com/jobseekers/Login.aspx?SkinId=Default");
NameValuePair v1 = new NameValuePair(
"__VIEWSTATE",
"/wEPDwUJNDc3ODI3MzM3D2QWAgIDD2QWBAILDw9kFgIeDGF1dG9jb21wbGV0ZQUDb2ZmZAINDw8WAh4EVGV4dAUY55m75b2V55So5oi35ZCN5LiN5a2Y5ZyoZGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFCGJ0bkxvZ2lue9S1/FB8b3fFVXy7iDffObaT+Iw=");
NameValuePair v2 = new NameValuePair("__EVENTVALIDATION",
"/wEWBAKztpHiCwKl1bKzCQK1qbSRCwKC3IeGDNbrqRqhGg9TthU1uDa3AeymTebG");
NameValuePair v3 = new NameValuePair("txtUserName", USERNAME);
NameValuePair v4 = new NameValuePair("txtPassword", PASSWORD);
NameValuePair v5 = new NameValuePair("btnLogin.x", "35");
NameValuePair v6 = new NameValuePair("btnLogin.y", "9");
post.setRequestBody(new NameValuePair[] { v1, v2, v3, v4, v5, v6 });
client.executeMethod(post);
System.out
.println("******************************登录******************************");
Cookie[] cookies = client.getState().getCookies();
post.releaseConnection();
int statuscode = post.getStatusCode();// 得到相应状态码
// 判断是否是请求转发 是的话请求转发的地址
if (statuscode == HttpStatus.SC_MOVED_TEMPORARILY)
sb.append("登录成功"+"\n");
else
sb.append("登录失败"+"\n");
System.out
.println("******************************首页******************************");
String newUrl = "http://www.cjol.com/jobseekers/default.aspx";
String s = "";
for (Cookie c : cookies) {
s += c + "; ";
}
GetMethod get = new GetMethod(newUrl);
get.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
get.setRequestHeader("Cookie", s);
get.setRequestHeader("Accept-Language", "zh-cn");
client.executeMethod(get);
String responseString = get.getResponseBodyAsString();
String regex = ">([0-9]+)</font></span><span[\\s]+id=\"labViewResumeCountTip";
sb.append("你的简历已被浏览了:" + oneStr(regex, responseString)
+ "次"+"\n");
get.releaseConnection();
System.out
.println("******************************刷新的内容******************************");
String resumeUrl = "http://www.cjol.com/jobseekers/Resume/UpdateResume.aspx";
get = new GetMethod(resumeUrl);
get.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
get.setRequestHeader("Cookie", s);
get.setRequestHeader("Accept-Language", "zh-cn");
client.executeMethod(get);
if (get.getResponseBodyAsString().indexOf("简历刷新成功") > 0)
sb.append("简历刷新成功"+"\n");
else
sb.append("简历刷新失败"+"\n");
get.releaseConnection();
System.out
.println("******************************通知******************************");
String noticeUrl = "http://cjol.com/jobseekers/JobOpportunity/InterviewNotificationList.aspx";
get = new GetMethod(noticeUrl);
get.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
get.setRequestHeader("Cookie", s);
get.setRequestHeader("Accept-Language", "zh-cn");
client.executeMethod(get);
responseString = get.getResponseBodyAsString();
regex = "面试通知\\(([0-9]+)条\\)";
sb.append("你有:" + oneStr(regex, responseString) + "封面试通知"+"\n");
regex = "target=\"_blank\">([^<]*)</a>";
List<String> list = duoStr(regex, responseString);
for (String string : list) {
sb.append(string+"\n");
}
get.releaseConnection();
tv.setText(sb);
}
public String oneStr(String regex, String responseString) {
Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(responseString);
if (m.find()) {
return m.group(1);
}
return "";
}
public List<String> duoStr(String regex, String responseString) {
List<String> list = new ArrayList<String>();
Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(responseString);
while (m.find()) {
list.add(m.group(1));
}
return list;
}
@Override
public void onClick(View v) {
try {
main();
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
- 1
- 2
前往页