web前端|js教程
httpclient,模拟登陆
web前端-js教程
httpclient模拟登陆(使用js设置cookie)
过年源码,ubuntu窗口无法移动,如何开发爬虫软件,php编程265,seo是方法lzw
document.cookie=utmpnum=51;path=/;domain=. + window.location.host
document.cookie=utmpkey=4732;path=/;domain=. + window.location.host
document.cookie=utmpuserid=yay;path=/;domain=. + window.location.host
h4ttpclient 4.3:
代源码2吉吉,pro 5刷ubuntu,成都乌龟爬虫市场,keys php,冀州seo排名lzw
最简单的方法就是通过得到的cookie定制一个httpclient,根据上面的例子,方法如下:
秒赞源码最新,写游戏用vscode还是vs,ubuntu解压替换,用tomcat改线程,爬虫变现模式,php项目运行环境,seo网络推广产品关键词lzw
CookieStore cookieStore = new BasicCookieStore();
for (int i = 0; i < 3; i++) {
String name;
String value;
int flag=s.indexOf("document.cookie");
s=s.substring(flag+17);
flag=s.indexOf(=);
name=s.substring(0, flag);
value=s.substring(flag+1, s.indexOf(;));
BasicClientCookie cookie = new BasicClientCookie(name,
value);
cookie.setVersion(0);
cookie.setDomain("."); //这个网址对应的是window.location.host的返回值
cookie.setPath("/");
cookieStore.addCookie(cookie);
}
// Set the store
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCookieStore(cookieStore)
.build();
android:
我找了半天也没找到上面方法对应的API,只能在每次访问前加cookie了
String cookie="";
for (int i = 0; i < 3; i++) {
String name;
String value;
int flag=s.indexOf("document.cookie");
s=s.substring(flag+17);
flag=s.indexOf(=);
name=s.substring(0, flag);
value=s.substring(flag+1, s.indexOf(;));
cookie +=name +"="+value;
if(i!=2)
cookie+=";";
}
/*
* 每次访问网络
*/
HttpGet httpget = new HttpGet(url);
httpget.addHeader("Cookie",cookie);
//如果httpclient中已经有cookie可能需要设置httpclient的cookie策略,具体可查官方API (:
HttpResponse response = httpclient.execute(httpget);
ps:如果是用java SE,也可以使用htmlunit类,它会执行js。