http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 5863|回复: 3

[例子] wordpress发帖

[复制链接]
发表于 2014-11-13 16:14:32 | 显示全部楼层 |阅读模式
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DotNet.Utilities;
using System.Text.RegularExpressions;

namespace wordpressDEMO
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string cookie="";
            string postdata = "log=admin&pwd=admin&rememberme=forever&wp-submit=%E7%99%BB%E5%BD%95&redirect_to=http%3A%2F%2Flocalhost%3A90%2Fwp-admin%2F&testcookie=1";
            
            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL="http://localhost:90/wp-login.php",
                Method="post",
                ContentType = "application/x-www-form-urlencoded",
                Postdata=postdata,
                //Allowautoredirect=true,
            };
            HttpResult result = http.GetHtml(item);

            Regex reg = new Regex(@"wordpress_\S*;");
            MatchCollection mts = reg.Matches(result.Cookie);
            foreach (Match itemformhash in mts)
            {

                cookie += itemformhash.Value;
            }
            textBox1.Text = cookie;
            item = new HttpItem()
            {
                URL = "http://localhost:90/wp-admin/post-new.php",
                Cookie = cookie,


            };
            result = http.GetHtml(item);
            textBox1.Text = result.Html;

            string _wpnonce = GetValue(result.Html, "name=\"_wpnonce\" value=\"", "\" />");
            string uid = GetValue(result.Html, "name=\"user_ID\" value=\"", "\" />");
            string postid = GetValue(result.Html, "name='post_ID' value='", "' />");
            string meta_box_order_nonce = GetValue(result.Html, "name=\"meta-box-order-nonce\" value=\"", "\" />");
            string closedpostboxesnonce = GetValue(result.Html, "name=\"closedpostboxesnonce\" value=\"", "\" />");
            string samplepermalinknonce = GetValue(result.Html, "name=\"samplepermalinknonce\" value=\"", "\" />");
            string _ajax_nonce_add_category = GetValue(result.Html, "name=\"_ajax_nonce-add-category\" value=\"", "\" />");
            string _ajax_nonce_add_meta = GetValue(result.Html, "name=\"_ajax_nonce-add-meta\" value=\"", "\" />");
            string encoding = GetValue(result.Html, "charset=", "\"");
            postdata = string.Format("_wpnonce={0}&_wp_http_referer=%2Fwp-admin%2Fpost-new.php&user_ID={1}&action=editpost&originalaction=editpost&post_author={1}&post_type=post&original_post_status=auto-draft&referredby=http%3A%2F%2Flocalhost%3A90%2Fwp-login.php%3Fredirect_to%3Dhttp%253A%252F%252Flocalhost%253A90%252Fwp-admin%252Fpost-new.php%26reauth%3D1&_wp_original_http_referer=http%3A%2F%2Flocalhost%3A90%2Fwp-login.php%3Fredirect_to%3Dhttp%253A%252F%252Flocalhost%253A90%252Fwp-admin%252Fpost-new.php%26reauth%3D1&auto_draft=&post_ID={2}&meta-box-order-nonce={3}&closedpostboxesnonce={4}&post_title={5}&samplepermalinknonce={6}&content={7}&wp-preview=&hidden_post_status=draft&post_status=draft&hidden_post_password=&hidden_post_visibility=public&visibility=public&post_password=&aa=2014&mm=11&jj=06&hh=10&mn=37&ss=03&hidden_mm=11&cur_mm=11&hidden_jj=06&cur_jj=06&hidden_aa=2014&cur_aa=2014&hidden_hh=10&cur_hh=10&hidden_mn=37&cur_mn=37&original_publish=%E5%8F%91%E5%B8%83&publish=%E5%8F%91%E5%B8%83&post_format=0&post_category%5B%5D=0&post_category%5B%5D=1&newcategory=%E6%96%B0%E5%88%86%E7%B1%BB%E7%9B%AE%E5%BD%95%E5%90%8D&newcategory_parent=-1&_ajax_nonce-add-category={8}&tax_input%5Bpost_tag%5D=%E6%B5%8B%E8%AF%95&newtag%5Bpost_tag%5D=&excerpt=&trackback_url=&metakeyinput=&metavalue=&_ajax_nonce-add-meta={9}&advanced_view=1&comment_status=open&ping_status=open&post_name=&post_author_override=1", _wpnonce, uid, postid, meta_box_order_nonce, closedpostboxesnonce, "测试吧", samplepermalinknonce, "测试吧测试吧测试吧测试吧测试吧", _ajax_nonce_add_category, _ajax_nonce_add_meta);
            item = new HttpItem()
            {
                URL = "http://localhost:90/wp-admin/post.php",
                PostEncoding = System.Text.Encoding.GetEncoding(encoding.Trim()),
                Method = "post",
                ContentType = "application/x-www-form-urlencoded",
                Postdata = postdata,
                Cookie = cookie,
                Referer = "http://localhost:90/wp-admin/post-new.php",
            };
            result = http.GetHtml(item);
            textBox1.Text = result.Html;

        }


        /// <summary>
        /// 获得字符串中开始和结束字符串中间得值
        /// </summary>
        /// <param name="str">字符串</param>
        /// <param name="s">开始</param>
        /// <param name="e">结束</param>
        /// <returns></returns>
        public static string GetValue(string str, string s, string e)
        {
            Regex rg = new Regex("(?<=(" + s + "))[.\\s\\S]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline);
            return rg.Match(str).Value;
        }
    }
}



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-11-14 14:15:20 | 显示全部楼层
看过帖子回复一下是个好习惯
发表于 2014-11-22 10:10:30 | 显示全部楼层
里边的网站用户名和密码 怎么post过去额?
发表于 2017-8-27 10:38:05 | 显示全部楼层
厉害了~感谢一下,直接拿来就能用哈。感谢感谢~
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-12-22 19:20

© 2014-2021

快速回复 返回顶部 返回列表