设为首页 加入收藏

TOP

java利用url解析网页内容并模拟手动form提交数据(四)
2014-11-24 12:02:33 来源: 作者: 【 】 浏览:180
Tags:java 利用 url 解析 网页 内容 模拟 手动 form 提交 数据
s & do rate of user review
List lsit = content.getHeaders().get("Set-Cookie");
Map resmap = new HashMap();
if (lsit != null) {
StringBuffer sb = new StringBuffer();
boolean isLast = false;
int i = 0;
for (String val : lsit) {
i++;
if (i == lsit.size()) {
isLast = true;
}
int pos = val.indexOf("=");
if (pos != -1) {
String cookieName = val.substring(0, pos);
String cookieva l = val.substring(pos + 1);
System.out.println(cookieName+":"+cookieva l);
cookieva l = cookieva l.split(";")[0];
if (isLast) {
sb.append(cookieName + "=" + cookieva l);
} else {
sb.append(cookieName + "=" + cookieva l + ";");
}
}
} System.out.println(sb.toString());
resmap.put("Cookie", sb.toString());
}
String a="";
System.out.print("请输入验证码:");
BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));
try {
a=strin.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("输入的数是:"+a);
String email = "xsl0218";
String pass = "zqs021823";
String loginUrl = "http://www.haoshijia.com.cn/register/index/logincheck";
String rateReviewUrl = "http://www.haoshijia.com.cn/member/index/index";
Map paramMap = new HashMap();
paramMap.put("login_name", email);
paramMap.put("login_password", pass);
//paramMap.put("login", "1");
paramMap.put("login_code", a+"");
content = curl("POST", loginUrl, paramMap, resmap, false,"");
//System.out.println(content.getBody());
// build request headers & do rate of user review
paramMap = new HashMap();
content = curl("POST", rateReviewUrl, paramMap, resmap, false,"");
inFile(content.getBody(), "D:/sss.txt");
System.out.println(content.getBody());
}
// 这个是输出
public static boolean inFile(String content, String path) {
PrintWriter out = null;
File file = new File(path);
try {
if (!file.exists()) {
file.createNewFile();
}
out = new PrintWriter(new FileWriter(file));
out.write(content);
out.flush();
return true;
} catch (Exception e) {
e.printStackTrace();
} finally {
out.close();
}
return false;
}
public static String getHtmlReadLine(String httpurl){
String CurrentLine="";
String TotalString="";
InputStream urlStream;
String content="";
try {
URL url = new URL(httpurl);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.connect();
System.out.println(connection.getResponseCode());
urlStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(
首页 上一页 1 2 3 4 5 下一页 尾页 4/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Maven使用教程 下一篇java实现u盘指定内容的自动复制

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: