JAVA 人人网 自动发帖,留言的情况

Eniak 2011-12-08 08:29:51
一宿没睡,想看看 HttpClient 如何 登陆人人网自动发帖,留言的。应为自己在经营一个网站,想通过这个方式,自动登录发帖,发些软文广告。


有三个问题,如下:

1 登陆不成问题了,但是发帖,留言还不成的。帮忙高手看看。我感觉是可能参数没有传对的原因,请见下面,// 传说种的参数问题

2 另外,我看了一些朋友是通过 Wireshark 来捕获数据包,分析在提交的时候应该提交什么,我试了一下,手动提交的时候一堆一堆的 get 和 post 也不知道哪个是最后文章的 pos 和 get, 有高手能教教吗,怎么看,一些基本的我会,比如特定侦听什么的。

3 提交的文章,里面有些关键词,应该如何加亮呢,比如,我在文章的最后添加一些关键字,我希望他们是红色的的,字体大一点的,谢谢了。



原来的程序转载于 http://www.iteye.com/topic/826988

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
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.protocol.HTTP;

/**
*
*
* Author : Saitkey < lei_d@foxmail.com >
*/
public class RenRenNotify {
private static HttpResponse response;
private static DefaultHttpClient httpClient;

public RenRenNotify(String userName, String password) {
this.httpClient = new DefaultHttpClient();
String loginForm = "http://www.renren.com/PLogin.do";
String origURL = "http://www.renren.com/Home.do";
String domain = "renren.com";
// 在首页表单上是隐藏的 抓包后分析,并没有发送到服务器
// String autoLogin = "true";
// 构造一个POST请求,利用Httclient提供的包
HttpPost httpPost = new HttpPost(loginForm);
// 将要发送的数据封包
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("email", userName));
params.add(new BasicNameValuePair("password", password));
params.add(new BasicNameValuePair("origURL", origURL));
params.add(new BasicNameValuePair("domain", domain));

// 封包添加到Post请求
try {
httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// 将 get 和post 方法包含到一个函数里面去,这里就是登陆过程了。
response = postMethod(httpPost);

/* 有跳转 System.out.println(response.getStatusLine());//返回302
Header[]headers=response.getAllHeaders(); for (int i = 0; i <
headers.length; i++) { Header header = headers[i];
System.out.println(header.getName()+": "+header.getValue()); }
*/
// 读取跳转的地址
// String redirectUrl = response.getFirstHeader("Location").getValue();
// 查看一下跳转过后,都出现哪些内容.
// response=getMethod(redirectUrl);//函数见后面
// System.out.println(response.getStatusLine()); // HTTP/1.1 200 OK

// 读取一下主页都有什么内容 已经登陆进去
// System.out.println(readHtml("http://www.renren.com/home"));
}

// 嗅探指定页面的代码
public String notify(String url) {
HttpGet get = new HttpGet(url);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String txt = null;
try {
txt = httpClient.execute(get, responseHandler);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
get.abort();
}




//String rest = txt.substring(index);

// 传说种的参数问题
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("title", "测试题目"));
params.add(new BasicNameValuePair("body", "测试的内容"));
// params.add(new BasicNameValuePair("origURL", origURL));
// params.add(new BasicNameValuePair("domain", domain));

HttpPost httpPost = new HttpPost("http://blog.renren.com/blog/0/addBlog");

// 封包添加到Post请求
try {
httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// 将 get 和post 方法包含到一个函数里面去,这里就是登陆过程了。
response = postMethod(httpPost);


return txt;
}

// 用post方法向服务器请求 并获得响应,因为post方法要封装参数,因此在函数外部封装好传参
public HttpResponse postMethod(HttpPost post) {
HttpResponse resp = null;
try {
resp = httpClient.execute(post);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
post.abort();
}
return resp;
}

// 用get方法向服务器请求 并获得响应
public HttpResponse getMethod(String url) {
HttpGet get = new HttpGet(url);
HttpResponse resp = null;
try {
resp = httpClient.execute(get);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
get.abort();
}
return resp;
}

public static void main(String[] args) {
RenRenNotify notify = new RenRenNotify("登陆邮箱",
"密码");
System.out.println(notify
.notify("http://blog.renren.com/NewEntry.do"/*"http://www.renren.com/home"*/));
}

}

...全文
366 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
现在有做出来了吗
Eniak 2011-12-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zqfddqr 的回复:]

你是想玩java还是想发帖


单纯想发帖换按键精灵
[/Quote]

两者兼顾,按键精灵不能编辑文章,我把文章存在一个数据库里面,然后每天就随机抽取几个,发帖了
xiaoping0505 2011-12-08
  • 打赏
  • 举报
回复
呵呵,挺牛~!
zqfddqr 2011-12-08
  • 打赏
  • 举报
回复
你是想玩java还是想发帖


单纯想发帖换按键精灵

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧