日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 模拟登陆人人网_java模拟登陆人人,通过验证码

發布時間:2023/12/20 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 模拟登陆人人网_java模拟登陆人人,通过验证码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

之前想要爬取人人上的一些信息,因為需要登陸,所以就從網上直接拷貝了一份代碼來實現人人登陸,但發現搜素到的大部分都沒有實現驗證碼驗證。故自己添加了驗證碼驗證,當然自己偷懶,沒有解析圖片,而是直接把圖片保存到本地,還需要手動輸入驗證碼。當然登陸成功之后,就可以爬取大量的其他人的信息,這里只返回的自己的頁面的源碼。

public class RenrenLogin {

public static String userName = "xxxx@126.com";

public static String? password = "xxxxx";

public static String redirectURL = "http://www.renren.com/home";

public static String renRenLoginURL = "http://www.renren.com/PLogin.do";

private HttpResponse response;

private HttpResponse resPic;

public static String picUrl = "http://icode.renren.com/getcode.do?t=web_login&rnd=Math.random()";

private HttpClient httpClient = new DefaultHttpClient();

public static void main(String []args) throws IOException{

RenrenLogin rl = new RenrenLogin();

rl.printText();

}

private void getPic(){

try {

HttpGet httpget=new HttpGet(picUrl);

resPic = httpClient.execute(httpget);

HttpEntity entity = resPic.getEntity();

InputStream is = entity.getContent();

FileOutputStream out = new FileOutputStream (new File("F:\\new.png"));

int read = 0;

byte[]bytes=new byte[1024];

while((read=is.read(bytes))!=-1)

out.write(bytes,0,read);

is.close();

out.flush();

out.close();

} catch (IllegalStateException e1) {

e1.printStackTrace();

} catch (IOException e1) {

e1.printStackTrace();

}

}

public? boolean login() throws IOException{

HttpPost httpPost = new HttpPost(renRenLoginURL);

List nvps = new ArrayList();

nvps.add(new BasicNameValuePair("origURL", redirectURL));

nvps.add(new BasicNameValuePair("domain", "renren.com"));

nvps.add(new BasicNameValuePair("isplogin", "false"));

nvps.add(new BasicNameValuePair("formName", ""));

nvps.add(new BasicNameValuePair("method", "post"));

nvps.add(new BasicNameValuePair("submit", "登錄人人網"));

nvps.add(new BasicNameValuePair("email", userName));

nvps.add(new BasicNameValuePair("password", password));

nvps.add(new BasicNameValuePair("autoLogin", "true"));

BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));

getPic();//下載圖片并保存到本地,自己需打開圖片查看

System.out.println("請到F盤查看圖片驗證碼并在控制臺中輸入:");

nvps.add(new BasicNameValuePair("icode", strin.readLine().toString()));

nvps.add(new BasicNameValuePair("key_id", "1"));

nvps.add(new BasicNameValuePair("captcha_type", "web_login"));

try {

httpPost.setEntity(new UrlEncodedFormEntity(nvps,? HTTP.UTF_8));

response = httpClient.execute(httpPost);

System.out.println(response.getStatusLine());

System.out.println(response.getParams());

System.out.println(response.getFirstHeader("Location").getValue());

} catch (Exception e) {

e.printStackTrace();

return false;

}? finally{

httpPost.abort();

}

return true;

}

public String getText(String redirectLocation){

HttpGet httpGet = new HttpGet(redirectLocation);

ResponseHandler 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;

}

private String getRedirectLocation() {

Header locationHeader = response.getFirstHeader("Location");

if (locationHeader == null) {

return null;

}

return locationHeader.getValue();

}

private void printText() throws IOException{

if(login()){

String redirectLocation = getRedirectLocation();

if (redirectLocation != null) {

System.out.println(getText(redirectLocation));

}

}

}

總結

以上是生活随笔為你收集整理的java 模拟登陆人人网_java模拟登陆人人,通过验证码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。