首页 技术 正文
技术 2022年11月23日
0 收藏 924 点赞 2,122 浏览 1643 个字

Java爬虫——模拟登录知乎

登录界面,首先随意输入一个账号,登录查看发送表单的请求

Java爬虫——模拟登录知乎

可以发现请求是Post : https://www.zhihu.com/login/phone_num

发送的表单是

_xsrf: 
password: 密码 无需加密
captcha: 验证码 无需验证码时为不用此项 ,需要验证码时为验证码图片倒立字体坐标
captcha_type:cn
phone_num: 账号
 package 知乎模拟登录; import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils; import java.util.ArrayList;
import java.util.List; public class GetProblem {
public static void main(String[] args) throws Exception {
CloseableHttpClient closeableHttpClient = HttpClients.createDefault() ;
HttpPost httpPost = new HttpPost("https://www.zhihu.com/login/phone_num") ;
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("_xsrf", "66653239623962342d396237632d346233332d396331362d333434386438326438616139"));
nvps.add(new BasicNameValuePair("password", "33665511886622"));
nvps.add(new BasicNameValuePair("captcha_type", "cn"));
nvps.add(new BasicNameValuePair("phone_num", "15890956765")); httpPost.setEntity(new UrlEncodedFormEntity(nvps));
CloseableHttpResponse closeableHttpResponse = closeableHttpClient.execute(httpPost) ;
HttpEntity entity = closeableHttpResponse.getEntity() ;
String s = EntityUtils.toString(entity);
System.out.println(s);
}
}

可能出现的情况

请求返回体为:

    {

  ”r”: 1,
  ”errcode”: 1991829,
  ”data”: {“captcha”:”\u9a8c\u8bc1\u7801\u9519\u8bef”},
  ”msg”: “\u9a8c\u8bc1\u7801\u9519\u8bef”
 }

“errcode”: 1991829

微信扫一扫

支付宝扫一扫

本文网址:https://www.zhankr.net/141338.html

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:7,140
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:4,476
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:566 阅读:5,286
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:5,162
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:6,335
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:3,873