C#推送URL链接到百度搜索资源平台快速收录URL网址

  C#推送URL链接到百度搜索资源平台快速收录URL网址


C#推送链接URL到百度搜索资源平台提高收录量

百度站长平台链接提交的主动推送(实时)是最为快速的提交方式,推荐您将站点当天新产出链接立即通过此方式推送给百度,以保证新链接可以及时被百度收录。






C# Code:

/// <summary>
/// C#推送链接URL到百度搜索资源平台提高收录量
/// </summary>
public class BaiduUrlRecorder
{
  
/// <summary>
  
/// 百度推送接口调用地址
  
/// </summary>
  
private const string api_url_post = "http://data.zz.baidu.com/urls?site={0}&token={1}";
  
private const string api_url_del = "http://data.zz.baidu.com/urls?site={0}&token={1}";
  
private const string api_url_update = "http://data.zz.baidu.com/urls?site={0}&token={1}";
  
  
string _siteName = "";
  
string _token = "";
  
  
static BaiduUrlRecorder _Instance = null;
  
  
public static BaiduUrlRecorder Instance
  {
    
get
    {
      
if (_Instance == null)
      _Instance
= new BaiduUrlRecorder("www.systables.com", "80MIjtCZFtVbQe3kP");
      
      
return _Instance;
    }
  }
  
  
public BaiduUrlRecorder(string siteName, string token)
  {
    _siteName
= siteName;
    _token
= token;
  }
  
  
/// <summary>
  
/// 推送链接URL到百度搜索资源平台
  
/// </summary>
  
/// <param name="url"></param>
  
/// <returns></returns>
  
public PostUrlToBaiduResponse Post(string url)
  {
    
return PostUrl(string.Format(api_url_post, _siteName, _token), url);
  }
  
  
/// <summary>
  
/// 更新链接url
  
/// </summary>
  
/// <param name="url"></param>
  
/// <returns></returns>
  
public PostUrlToBaiduResponse Update(string url)
  {
    
return PostUrl(string.Format(api_url_update, _siteName, _token), url);
  }
  
  
/// <summary>
  
/// 删除链接url
  
/// </summary>
  
/// <param name="url"></param>
  
/// <returns></returns>
  
public PostUrlToBaiduResponse Delete(string url)
  {
    
return PostUrl(string.Format(api_url_del, _siteName, _token), url);
  }
  
  
/// <summary>
  
/// POST方式调用百度站长平台(资源搜索平台)API接口
  
/// </summary>
  
/// <param name="baidu_api_url">百度API接口</param>
  
/// <param name="my_url">URL地址</param>
  
/// <returns></returns>
  
private PostUrlToBaiduResponse PostUrl(string baidu_api_url, string my_url)
  {
    Stream outstream
= null;
    Stream instream
= null;
    StreamReader sr
= null;
    HttpWebResponse response
= null;
    HttpWebRequest request
= null;
    
    
// 准备请求...
    
try
    {
      Encoding encoding
= System.Text.Encoding.GetEncoding("gb2312");
      
byte[] data = encoding.GetBytes(my_url);
      
      
// 设置参数
      
request = WebRequest.Create(baidu_api_url) as HttpWebRequest;
      
      CookieContainer cookieContainer
= new CookieContainer();
      request.UserAgent
= "curl/7.12.1";
      request.CookieContainer
= cookieContainer;
      request.AllowAutoRedirect
= true;
      request.Method
= "POST";
      request.ContentType
= "text/plain";
      request.ContentLength
= data.Length;
      
      outstream
= request.GetRequestStream();
      outstream.Write(data,
0, data.Length);
      outstream.Close();
      
      
//发送请求并获取相应回应数据
      
response = request.GetResponse() as HttpWebResponse;
      
//直到request.GetResponse()程序才开始向目标网页发送Post请求
      
instream = response.GetResponseStream();
      sr
= new StreamReader(instream, encoding);
      
      
//返回结果网页(html)代码
      
string content = sr.ReadToEnd();
      
string err = string.Empty;
      
      PostUrlToBaiduResponse ret
= Newtonsoft.Json.JsonConvert.DeserializeObject<PostUrlToBaiduResponse>(content);
      
return ret;
    }
    
catch (Exception ex)
    {
      
//提交异常,出错原因有:token is not valid,远程服务器返回错误: (401) 未经授权。
      
return new PostUrlToBaiduResponse { error = -1, message = ex.Message };
    }
  }
}


//来源:C/S框架网 | www.csframework.com | QQ:23404761




C# Code:


/// <summary>
/// 百度服务器回应
/// </summary>
public class PostUrlToBaiduResponse
{
  
public int remain { get; set; }
  
public int success { get; set; }
  
public int error { get; set; }
  
public string message { get; set; }
  
  
public override string ToString()
  {
    
return $"remain:{remain},success:{success},error:{error},message:{message}";
  }
}

//来源:C/S框架网 | www.csframework.com | QQ:23404761




推送1条URL:


C# Code:

//推送百度收录
string urlTmp = "http://www.systables.com/tables/show-21030317534215466809.html";
PostUrlToBaiduResponse response
= BaiduUrlRecorder.Instance.Post(urlTmp);
string baidu = (response != null && response.success == 1 ? "百度推送成功!" : "");

//来源:C/S框架网 | www.csframework.com | QQ:23404761




批量推送n条URL(***URL必须用断行符分开***):



C# Code:

StringBuilder sb = new StringBuilder();

foreach (DataRow R in dt.Rows) sb.AppendLine(R["URL"].ToString());

string urlTmp = sb.ToString();

PostUrlToBaiduResponse response
= BaiduUrlRecorder.Instance.Post(urlTmp);


//来源:C/S框架网 | www.csframework.com | QQ:23404761




百度搜索资源平台




贴图图片-baidu_url_post




C/S框架网|原创精神.创造价值.打造精品

扫一扫加微信
C/S框架网作者微信 C/S框架网|原创作品.质量保障.竭诚为您服务



版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
C/S框架网
发表评论

评论内容
昵称:
关联文章

C#URL搜索资源平台快速收录URL网址
C#URL搜索资源平台提高收录
C#主动POSTURL站长平台(支持提交、更新和删除URL
Winform开发平台搜索结果
C#模拟搜索长词自动语义匹配,使用分词算法抽取关键词
C#使用分词算法从文本字符串中抽取关键词模拟搜索|CSFramework.COM巨献
官网搜索引擎SEO,关键词SEO,搜索分词系统一体化解决方案
模拟搜索渲染HTML页面关键词高亮分组排序算法(C#)
热烈祝贺C/S框架网搜索关键字排名第一
C/S快速开发框架多语言功能集成翻译接口(支持中文简体、繁体、英文、越南文)
GitBlit - 创建、VS解决方案源码添加版本库
.NET WebApi后端开发框架-微信小程序消息订阅与案例详解
C#.Net快速开发平台|Winform快速开发平台介绍
C/S架构快速开发平台提供高级查询功能 - 自定义查询条件搜索数据
C# Model对象实例转换为URL网址参数Param形式
Google和Baidu搜索引擎对比(要加油啊)
CSFramework模拟搜索引擎自动语义分析分词算法(C#)
C# 地图坐标获取详细地址
众里寻她千,蓦然回首,C/S框架就在www.csframework.com...
SqlServer配置服务器LINKSERVER:ODBC连接MySQL数据库