如何转发别人的博客

【转】博客转发小工具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              ifstring .IsNullOrEmpty(url)|| string .IsNullOrEmpty(url.Trim()))
 9                  return  null ; // 如果url为空则立刻返回
10              结果result = new Result();
11             HtmlWeb htmlWeb = new HtmlWeb();
12              试试
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              返回结果;
21          }

二:复制页面内容

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

三:粘贴内容发布

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

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

如何转发别人的博客

贴图了

 如何转发别人的博客如何转发别人的博客

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

1  使用HtmlAgilityPack;
2  使用系统;
3  using System.Collections.Generic;
4  使用System.ComponentModel;
5  使用System.Data;
6  使用System.Drawing;
7  使用System.Text;
8  使用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</span><span style =”颜色:#008000;“>”;           
22              结果re = getList(txt_url.Text);
23              if(re == null 24              {
 25                  MessageBox.Show(请输入正确博客园的博客地址〜); 返回;
26             }
 27               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(已经成功复制到粘贴板〜);
  
          <summary> 
35          /// 抓取方法
 36          ///  </ summary> 
37          ///  <param name =“url”> url地址</ param> 
38          ///  <returns> </ returns> 
39          public结果getList(string url)
 40          {
 41              ifstring .IsNullOrEmpty(url)|| string .IsNullOrEmpty(url.Trim()))
 42                  返回 null ; // 如果url为空则立刻返回
43              结果result = new Result();
44              HtmlWeb htmlWeb =新的HtmlWeb();
45              尝试
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              返回结果;
54          }
 55      }
 56  
57      public  class Result
 58      {
 59          ///  <summary> 
60          /// 链接
 61          ///  </ summary> 
62          public  string url { get ; 设置; }
 63          ///  <summary> 
64          /// 标题
 65          ///  </ summary> 
66          公共 字符串title { get ; 设置; }
 67          ///  <summary> 
68          /// 正文内容
 69          ///  </ summary> 
70          public  string content { get ; 设置; }
 71      }
 72 }

 

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

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