⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testhexun.java

📁 和讯发评论 和讯发评论 和讯发评论 和讯发评论 和讯发评论 和讯发评论 和讯发评论
💻 JAVA
字号:
/**
 * 
 */
package org.hx.linjk;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.httpclient.params.HttpMethodParams;

/**
 * @author linjk 2007-9-1 下午10:42:13 linjk03@163.com
 */
public class Testhexun {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Testhexun thxu = new Testhexun();
		String LoginName = "说洋";
		String yousite = "http://";
		String tmpCommentTitle = "发表详论";
		String tmpCommentContent = "发表详论 --支持!!!!!!!!!!!";
		try{
			List list=getUrlList();
			for(int i=0;i<list.size();i++){
				String postUrl = PostMethodUrl((String)list.get(i));;
				String viewUrl = (String)list.get(i);
				if(!postUrl.equals(""))
				thxu.sendHexunPinLuen(LoginName, yousite, postUrl, viewUrl,
						tmpCommentTitle, tmpCommentContent);
				System.out.println("+++++++++++++++++++++第"+i+"个评论已经完成++++++++++++++++++++++++++++");
			}
		
		}catch(Exception exx){
			
		}

/*
		
		 * http://comment.blog.hexun.com/NBD9257/postComment.aspx?ArticleID=11697174
		 * http://nbd9257.blog.hexun.com/11697174_d.html
		 
		postUrl = "http://comment.blog.hexun.com/NBD9257/postComment.aspx?ArticleID=11697174";
		viewUrl = "http://nbd9257.blog.hexun.com/11697174_d.html";
		tmpCommentTitle = "Re: 出口官员,哪个国家能上这个当?";
		tmpCommentContent = "支持!!!!!!!!!!!";
		thxu.sendHexunPinLuen(LoginName, yousite, postUrl, viewUrl,
				tmpCommentTitle, tmpCommentContent);
		*//**
		 * http://comment.blog.hexun.com/NBD9257/postComment.aspx?ArticleID=11648217
		 * http://nbd9257.blog.hexun.com/11648217_d.html
		 *//*
		postUrl = "http://comment.blog.hexun.com/NBD9257/postComment.aspx?ArticleID=11648217";
		viewUrl = "http://nbd9257.blog.hexun.com/11648217_d.html";
		tmpCommentTitle = "Re: 天水市出现强降雨天气";
		tmpCommentContent = "支持!!!!!!!!!!!";
		thxu.sendHexunPinLuen(LoginName, yousite, postUrl, viewUrl,
				tmpCommentTitle, tmpCommentContent);
		*//**
		 * http://comment.blog.hexun.com/ksaaa112/postComment.aspx?ArticleID=11476944
		 * http://ksaaa112.blog.hexun.com/11476944_d.html
		 *//*
		postUrl = "http://comment.blog.hexun.com/ksaaa112/postComment.aspx?ArticleID=11476944";
		viewUrl = "http://ksaaa112.blog.hexun.com/11476944_d.html";
		tmpCommentTitle = "Re: 文爷爷等艺术家是否有资格下葬八宝山革命公墓?";
		tmpCommentContent = "支持!!!!!!!!!!!";
		thxu.sendHexunPinLuen(LoginName, yousite, postUrl, viewUrl,
				tmpCommentTitle, tmpCommentContent);
		*//**
		 * http://comment.blog.hexun.com/ksaaa112/postComment.aspx?ArticleID=11364034
		 * http://ksaaa112.blog.hexun.com/11364034_d.html
		 *//*
		postUrl = "http://comment.blog.hexun.com/ksaaa112/postComment.aspx?ArticleID=11364034";
		viewUrl = "http://ksaaa112.blog.hexun.com/11364034_d.html";
		tmpCommentTitle = "Re: 令人生疑的“人民的”";
		tmpCommentContent = "支持!!!!!!!!!!!";
		thxu.sendHexunPinLuen(LoginName, yousite, postUrl, viewUrl,
				tmpCommentTitle, tmpCommentContent);
		*//**
		 * http://comment.blog.hexun.com/lzh7005/postComment.aspx?ArticleID=11705733
		 * http://lzh7005.blog.hexun.com/11705733_d.html
		 *//*
		postUrl = "http://comment.blog.hexun.com/lzh7005/postComment.aspx?ArticleID=11705733";
		viewUrl = "http://lzh7005.blog.hexun.com/11705733_d.html";
		tmpCommentTitle = "Re: 给大家提个醒!以免被骗!!!";
		tmpCommentContent = "支持!!!!!!!!!!!";
		thxu.sendHexunPinLuen(LoginName, yousite, postUrl, viewUrl,
				tmpCommentTitle, tmpCommentContent);
		*/
		

	}

	/**
	 * 发布评论文章
	 * 
	 * @param LoginName
	 *            发表文章的作者名
	 * @param yousite网
	 *            址:
	 * @param postUrl
	 *            http://comment.blog.hexun.com/lzh7005/postComment.aspx?ArticleID=11705733
	 * @param viewUrl
	 *            http://lzh7005.blog.hexun.com/11705733_d.html
	 * @param tmpCommentTitle
	 *            回复标题
	 * @param tmpCommentContent
	 *            回复正文.
	 */
	public void sendHexunPinLuen(String LoginName, String yousite,
			String postUrl, String viewUrl, String tmpCommentTitle,
			String tmpCommentContent) {
		System.setProperty("org.apache.commons.logging.Log",
				"org.apache.commons.logging.impl.SimpleLog");
		System.setProperty("org.apache.commons.logging.simplelog.showdatetime",
				"true");
		System.setProperty("org.apache.commons.logging"
				+ ".simplelog.log.org.apache.commons.httpclient", "error");
		System.getProperties().setProperty("httpclient.useragent",
				"Mozilla/4.0");
		try {
			HttpClient httpClient = new HttpClient();

			// String url =
			// "http://comment.blog.hexun.com/tuoniang/postComment.aspx?ArticleID="+tmpArticleID;
			PostMethod postMethod = new PostMethod(postUrl);
			postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
					new DefaultHttpMethodRetryHandler());

			// StringPart ArticleID = new StringPart("ArticleID", tmpArticleID);
			StringPart UserNameTextbox = new StringPart("UserNameTextbox",
					LoginName, "GBK");
			StringPart UserUrlTextbox = new StringPart("UserUrlTextbox",
					yousite);
			StringPart CommentTitle = new StringPart("CommentTitle",
					tmpCommentTitle, "GB2312");
			StringPart CommentIDTxt = new StringPart("CommentIDTxt", "0");
			StringPart ReplyType = new StringPart("ReplyType", "");
			StringPart NoHtmlCommentContent = new StringPart(
					"NoHtmlCommentContent", tmpCommentContent, "GBK");
			Part[] parts = { UserNameTextbox, UserUrlTextbox, CommentTitle,
					CommentIDTxt, ReplyType, NoHtmlCommentContent };
			postMethod.setRequestEntity(new MultipartRequestEntity(parts,
					postMethod.getParams()));

			int statusCode = httpClient.executeMethod(postMethod);
			System.out.println(statusCode);
			String getHtml = postMethod.getResponseBodyAsString();
			if (getHtml.indexOf("<title>Object moved</title>") >= 0) {
				// viewUrl
				System.out.println(tmpCommentTitle + viewUrl + "发布评论成功!");

			}
			postMethod.releaseConnection();
		} catch (Exception e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
	}
	public static List getUrlList() {
		PreparedStatement pst = null;

		ResultSet rs = null;
		DbDataUtil ddu=new DbDataUtil();
		String DBAccessPathUrl="d:\\d.mdb";
		List list=new ArrayList();
		Connection conn=ddu.getDataBaseConn(DBAccessPathUrl);
		try {
			String sqlStr = "select art_Page from HexunComm";
			String sqlDel = "";
			pst = conn.prepareStatement(sqlStr);
			rs = pst.executeQuery();
			while (rs.next()) {
				list.add(rs.getString(1).toString().trim());
			}
			rs.close();
			
			if (pst != null)
				pst.close();
			conn.close();
			return list;// 成功
		} catch (Exception exx) {
			exx.printStackTrace();
			return null;// 失败
		} 
	}
	
	
	public static String PostMethodUrl (String getMethodUrl){
		try {
			HttpClient httpClient = new HttpClient();

			GetMethod getMethod = new GetMethod(
					getMethodUrl);

			int statusCode = httpClient.executeMethod(getMethod);
			System.out.println(statusCode);
			//流
			StringBuffer sbuf=new StringBuffer();
			BufferedReader in = new BufferedReader(new InputStreamReader(getMethod.getResponseBodyAsStream()));
			String inputLine;
			String UrlStrHtml="";
				while ((inputLine = in.readLine()) != null) {
					// 从输入流不断的读数据,直到读完为止
					if(inputLine.indexOf("<form name=\"postComment\"")>=0){
						UrlStrHtml=new String(inputLine.getBytes("GBK"));
						UrlStrHtml=urlStr(UrlStrHtml);
					}else
						sbuf.append( new String(inputLine.getBytes("GBK")));
				}
			in.close();
			if(!UrlStrHtml.equals("")){
				System.out.println(UrlStrHtml);
				getMethod.releaseConnection();
				return UrlStrHtml;
			}
			else{
				System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
				System.out.println("++++++++++++++++++++++++"+getMethodUrl+"++++++++++++++++++++++++");
				System.out.println(sbuf.toString());
				System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
				getMethod.releaseConnection();
				
			}
			return "";
		} catch (Exception e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
			return "";
		}
	}

	public static String urlStr(String StrHtml){
		int oneTw=StrHtml.indexOf("action");
		int twoTw=StrHtml.lastIndexOf("\">");
		String tmpStr=StrHtml.substring(oneTw+6, twoTw);
		tmpStr=tmpStr.replaceAll(" = ", "").trim();
		tmpStr=tmpStr.replaceAll("\"", "").trim();
		return tmpStr;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -