java實(shí)現(xiàn)京東登陸示例分享
package com.lkb.test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpResponse;
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.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.message.BufferedHeader;
import org.apache.http.protocol.HTTP;
import com.util.Constant;
public class JD {
// The configuration items
private static String redirectURL = "http://order.jd.com/center/list.action";
private static String loginUrl = "http://passport.jd.com/uc/login";
// Don't change the following URL
private static String renRenLoginURL = "https://passport.jd.com/uc/loginService";
// The HttpClient is used in one session
private HttpResponse response;
private DefaultHttpClient httpclient = new DefaultHttpClient();
public Map<String,String> getParams(){
Map<String,String> map = new HashMap<String,String>();
String str = getText(loginUrl);
String strs1[] = str.split("name=\"uuid\" value=\"");
String strs2[] = strs1[1].split("\"/>");
String uuid = strs2[0];
map.put("uuid", uuid);
System.out.println(strs2[0]);
String str3s[] = strs1[1].split("<span class=\"clr\"></span><input type=\"hidden\" name=\"");
String strs4[] = str3s[1].split("/>");
String strs5[] = strs4[0].trim().split("\"");
String key = strs5[0];
String value = strs5[2];
map.put(key, value);
return map;
}
private boolean login() {
Map map = getParams();
HttpPost httpost = new HttpPost(renRenLoginURL);
// All the parameters post to the web site
List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
nvps.add(new BasicNameValuePair("ReturnUrl", redirectURL));
nvps.add(new BasicNameValuePair("loginname", Constant.userName));
nvps.add(new BasicNameValuePair("nloginpwd", Constant.password));
nvps.add(new BasicNameValuePair("loginpwd", Constant.password));
Iterator it = map.keySet().iterator();
while(it.hasNext()) {
String key = it.next().toString();
String value = map.get(key).toString();
nvps.add(new BasicNameValuePair(key, value));
}
try {
httpost.setEntity(new UrlEncodedFormEntity((List<? extends org.apache.http.NameValuePair>) nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
httpost.abort();
}
return true;
}
private String getRedirectLocation() {
BufferedHeader locationHeader = (BufferedHeader) response.getFirstHeader("Location");
if (locationHeader == null) {
return null;
}
return locationHeader.getValue();
}
private String getText(String redirectLocation) {
HttpGet httpget = new HttpGet(redirectLocation);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = "";
try {
responseBody = httpclient.execute(httpget, responseHandler);
} catch (Exception e) {
e.printStackTrace();
responseBody = null;
} finally {
httpget.abort();
//httpclient.getConnectionManager().shutdown();
}
return responseBody;
}
public void printText() {
if (login()) {
System.out.println(getText(redirectURL));
String redirectLocation = getRedirectLocation();
if (redirectLocation != null) {
System.out.println(getText(redirectLocation));
}
}
}
public static void main(String[] args) {
JD renRen = new JD();
//renRen.getParams();
renRen.printText();
}
}
- jquery仿京東導(dǎo)航/仿淘寶商城左側(cè)分類導(dǎo)航下拉菜單效果
- Jquery仿淘寶京東多條件篩選可自行結(jié)合ajax加載示例
- java實(shí)現(xiàn)京東秒殺功能分享 京東秒殺軟件
- jquery 實(shí)現(xiàn)京東商城、凡客商城的圖片放大效果
- python抓取京東價(jià)格分析京東商品價(jià)格走勢
- 基于JavaScript實(shí)現(xiàn)仿京東圖片輪播效果
- Python抓取京東圖書評論數(shù)據(jù)
- python抓取京東商城手機(jī)列表url實(shí)例代碼
- jQuery簡單實(shí)現(xiàn)仿京東商城的左側(cè)菜單效果代碼
- Android仿京東首頁畫軸效果
相關(guān)文章
mybatisplus如何在xml的連表查詢中使用queryWrapper
這篇文章主要介紹了mybatisplus如何在xml的連表查詢中使用queryWrapper,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01SpringBoot 創(chuàng)建web項(xiàng)目并部署到外部Tomcat
本篇文章主要介紹了SpringBoot 創(chuàng)建web項(xiàng)目并部署到外部Tomcat,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06Springmvc中的轉(zhuǎn)發(fā)重定向和攔截器的示例
本篇文章主要介紹了Springmvc中的轉(zhuǎn)發(fā)重定向和攔截器的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05一小時(shí)迅速入門Mybatis之bind與多數(shù)據(jù)源支持 Java API
這篇文章主要介紹了一小時(shí)迅速入門Mybatis之bind與多數(shù)據(jù)源支持 Java API,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-09-09idea使用Maven Helper插件去掉無用的poom 依賴信息(詳細(xì)步驟)
這篇文章主要介紹了idea使用Maven Helper插件去掉無用的poom 依賴信息,本文分步驟給大家講解的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04Java設(shè)計(jì)模式之單一職責(zé)原則精解
設(shè)計(jì)模式(Design pattern)代表了最佳的實(shí)踐,通常被有經(jīng)驗(yàn)的面向?qū)ο蟮能浖_發(fā)人員所采用。設(shè)計(jì)模式是軟件開發(fā)人員在軟件開發(fā)過程中面臨的一般問題的解決方案。本篇介紹設(shè)計(jì)模式七大原則之一的單一職責(zé)原則2022-02-02淺談SpringBoot集成Quartz動(dòng)態(tài)定時(shí)任務(wù)
這篇文章主要介紹了SpringBoot集成Quartz動(dòng)態(tài)定時(shí)任務(wù),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04Apache?Commons?Imaging處理圖像實(shí)例深究
這篇文章主要為大家介紹了Apache?Commons?Imaging處理圖像的實(shí)例探索深究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12