We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我对OneSixThreeImporter做了一些修改,可以获得联系人了。其中contactsUrl 使用了 "http://tg4a84.mail.163.com/jy3/address/addrprint.jsp?",使用Jsoup解析DOM。
在pom中需增加jsoup: org.jsoup jsoup 1.7.3
OneSixThreeImporter代码: package com.huangzhimin.contacts.email;
import java.util.ArrayList; import java.util.Calendar; import java.util.List;
import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.NameValuePair; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements;
import com.huangzhimin.contacts.Contact; import com.huangzhimin.contacts.exception.ContactsException;
/**
导入163联系人列表
@author flyerhzm
*/ public class OneSixThreeImporter extends EmailImporter { // 登录url
private String loginUrl = "http://reg.163.com/login.jsp?type=1&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D3";
登录163邮箱
@throws ContactsException */ public void doLogin() throws ContactsException { try { NameValuePair params[] = { new NameValuePair("verifycookie", "1"), new NameValuePair("product", "mail163"), new NameValuePair("username", getUsername(email)), new NameValuePair("password", password), new NameValuePair("selType", "jy") }; Calendar calendar = Calendar.getInstance(); calendar.set(2099, 11, 31); client.getState().addCookies( new Cookie[] { new Cookie(".163.com", "ntes_mail_firstpage", "normal", "/", calendar.getTime(), false), new Cookie(".163.com", "loginType", "js", "/", calendar.getTime(), false) }); String responseStr = doPost(loginUrl, params, "http://mail.163.com/");
String redirectUrl = getJSRedirectLocation(responseStr); doGet(redirectUrl, loginUrl);
} catch (Exception e) { throw new ContactsException("163 protocol has changed", e); } }
进入联系人列表页面,并读取所有的联系人信息
@return 所有的联系人信息
@throws ContactsException */ public List parseContacts() throws ContactsException { try { String contactsUrl = "http://tg4a84.mail.163.com/jy3/address/addrprint.jsp?" + getSid(lastUrl); String content = doGet(contactsUrl);
List<Contact> contacts = new ArrayList<Contact>(); Document doc = Jsoup.parse(content); Elements names = doc.select(".gTitleSub .mTT"); Elements addresses = doc.select(".gTable tbody tr:first-child td"); int size = names.size(); for (int i = 0; i < size; i++) { String username = names.get(i).text().trim(); String email = addresses.get(i).text().trim(); contacts.add(new Contact(username, email)); } return contacts;
private String getSid(String url) { return url.substring(url.indexOf("sid="));
} }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
我对OneSixThreeImporter做了一些修改,可以获得联系人了。其中contactsUrl 使用了 "http://tg4a84.mail.163.com/jy3/address/addrprint.jsp?",使用Jsoup解析DOM。
在pom中需增加jsoup:
org.jsoup
jsoup
1.7.3
OneSixThreeImporter代码:
package com.huangzhimin.contacts.email;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.NameValuePair;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import com.huangzhimin.contacts.Contact;
import com.huangzhimin.contacts.exception.ContactsException;
/**
导入163联系人列表
@author flyerhzm
*/
public class OneSixThreeImporter extends EmailImporter {
// 登录url
private String loginUrl = "http://reg.163.com/login.jsp?type=1&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D3";
/**
*/
public OneSixThreeImporter(String email, String password) {
super(email, password, "UTF-8");
}
/**
登录163邮箱
@throws ContactsException
*/
public void doLogin() throws ContactsException {
try {
NameValuePair params[] = { new NameValuePair("verifycookie", "1"),
new NameValuePair("product", "mail163"),
new NameValuePair("username", getUsername(email)),
new NameValuePair("password", password),
new NameValuePair("selType", "jy") };
Calendar calendar = Calendar.getInstance();
calendar.set(2099, 11, 31);
client.getState().addCookies(
new Cookie[] {
new Cookie(".163.com", "ntes_mail_firstpage",
"normal", "/", calendar.getTime(), false),
new Cookie(".163.com", "loginType", "js", "/",
calendar.getTime(), false) });
String responseStr = doPost(loginUrl, params,
"http://mail.163.com/");
} catch (Exception e) {
throw new ContactsException("163 protocol has changed", e);
}
}
/**
进入联系人列表页面,并读取所有的联系人信息
@return 所有的联系人信息
@throws ContactsException
*/
public List parseContacts() throws ContactsException {
try {
String contactsUrl = "http://tg4a84.mail.163.com/jy3/address/addrprint.jsp?" + getSid(lastUrl);
String content = doGet(contactsUrl);
} catch (Exception e) {
throw new ContactsException("163 protocol has changed", e);
}
}
private String getSid(String url) {
return url.substring(url.indexOf("sid="));
}
}
The text was updated successfully, but these errors were encountered: