zoukankan      html  css  js  c++  java
  • 博客转发小工具1

    有些朋友在转发别人博客的时候会问,博客怎么转发的啊?让我一段一段的复制吗?那图片怎么办?隐藏代码要一个一个的打开了复制?

    对,很麻烦。费时费力。有的同学会说收藏不就可以了吗?收藏只是收藏了别人的地址,并没有收藏人家的全部内容。如果人家删除原文章,那就等于白收藏了。

    我不知道 博客园有没有一键转发的功能,反正我是没找到的。于是,闲来无事,做了个博客转发小工具。

    其实很简单,分三步。 

    一:取得页面内容

    取页面内容需要用到HtmlAgilityPack.dll 详细用法可以百度之。

     1          /// <summary>
     2         /// 抓取方法
     3         /// </summary>
     4         /// <param name="url">url地址</param>
     5         /// <returns></returns>
     6         public Result getList(string url)
     7         {
     8             if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(url.Trim()))
     9                 return null;//如果url为空 则立刻返回
    10             Result result = new Result();
    11             HtmlWeb htmlWeb = new HtmlWeb();
    12             try
    13             {
    14                 HtmlAgilityPack.HtmlDocument htmlDoc = htmlWeb.Load(url);
    15                 result.url = url;
    16                 result.content = htmlDoc.DocumentNode.SelectSingleNode("//div[@id='cnblogs_post_body']").InnerHtml;//这里是去div id为cnblogs_post_body的全部内容  也就是我们发布的博客全部内容
    17                 result.title = htmlDoc.DocumentNode.SelectSingleNode("//a[@id='cb_post_title_url']").InnerText; //取标题
    18             }
    19             catch (Exception) { return null; }
    20             return result;
    21         }

    二:复制页面内容

    Clipboard.SetText(txt_content.Text);//把内容复制到粘贴板

    三:粘贴内容发布

    这里就没有我的事了。你自己去后台发布就ok了。

    不过发布的时候要注意了。粘贴的时候一定要切换到html模式。

    贴图了

     

    这里贴出全部代码,因为代码量非常少,就放一个文件了。

     1 using HtmlAgilityPack;
     2 using System;
     3 using System.Collections.Generic;
     4 using System.ComponentModel;
     5 using System.Data;
     6 using System.Drawing;
     7 using System.Text;
     8 using System.Windows.Forms;
     9 
    10 namespace 博客转发
    11 {
    12     public partial class Form1 : Form
    13     {
    14         public Form1()
    15         {
    16             InitializeComponent();
    17         }
    18 
    19         private void button1_Click(object sender, EventArgs e)
    20         {
    21             //string url = @"http://www.cnblogs.com/zhaopei/p/4174811.html";           
    22             Result re = getList(txt_url.Text);
    23             if (re == null)
    24             {
    25                 MessageBox.Show("请输入正确博客园的博客地址~"); return;
    26             }
    27             string str = @"<a href='" + re.url + "'>【转】" + re.title + "</a><br/>";
    28             txt_content.Text = str + re.content;
    29             txt_title.Text = "【转】" + re.title;
    30             Clipboard.SetText(txt_content.Text);//把内容复制到粘贴板
    31             MessageBox.Show("已经成功复制到粘贴板~");
    32         }
    33 
    34         /// <summary>
    35         /// 抓取方法
    36         /// </summary>
    37         /// <param name="url">url地址</param>
    38         /// <returns></returns>
    39         public Result getList(string url)
    40         {
    41             if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(url.Trim()))
    42                 return null;//如果url为空 则立刻返回
    43             Result result = new Result();
    44             HtmlWeb htmlWeb = new HtmlWeb();
    45             try
    46             {
    47                 HtmlAgilityPack.HtmlDocument htmlDoc = htmlWeb.Load(url);
    48                 result.url = url;
    49                 result.content = htmlDoc.DocumentNode.SelectSingleNode("//div[@id='cnblogs_post_body']").InnerHtml;//这里是去div id为cnblogs_post_body的全部内容  也就是我们发布的博客全部内容
    50                 result.title = htmlDoc.DocumentNode.SelectSingleNode("//a[@id='cb_post_title_url']").InnerText; //取标题
    51             }
    52             catch (Exception) { return null; }
    53             return result;
    54         }
    55     }
    56 
    57     public class Result
    58     {
    59         /// <summary>
    60         /// 链接
    61         /// </summary>
    62         public string url { get; set; }
    63         /// <summary>
    64         /// 标题
    65         /// </summary>
    66         public string title { get; set; }
    67         /// <summary>
    68         /// 正文内容
    69         /// </summary>
    70         public string content { get; set; }
    71     }
    72 }

    程序下载 密码:5c6q  源码下载 密码:60fr

    如果大家有兴趣可以在此基础上进行自己的扩展和修改。

  • 相关阅读:
    my live health
    network / switchboard / jiaohuanji / switch
    my live boadband
    proxyServer Squid 3.5.5 / 20181111
    db mysql / mysql cluster 5.7.19 / performance
    MPTCP v0.92 Release
    MPTCP
    外国专家:区块链是新的Linux 而非新的互联网
    为什么用 Unity 3D 开发游戏是用 C# || JS 开发而不是用C++
    树莓派、 Arduino 、传统单片机开发板该如何选择?
  • 原文地址:https://www.cnblogs.com/zhaopei/p/4176370.html
Copyright © 2011-2022 走看看