当前位置: 首页>>代码示例>>C#>>正文


C# Page.ResolveRedirect方法代码示例

本文整理汇总了C#中DotNetWikiBot.Page.ResolveRedirect方法的典型用法代码示例。如果您正苦于以下问题:C# Page.ResolveRedirect方法的具体用法?C# Page.ResolveRedirect怎么用?C# Page.ResolveRedirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DotNetWikiBot.Page的用法示例。


在下文中一共展示了Page.ResolveRedirect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

	/// The entry point function. Start coding here.
	public static void Main()
	{
		// Compiled documentation is available in Documentation.chm file.

		// A very compehensive DotNetWikiBot usage examples can be found
		// in unit testing file called DebugBot.cs:
		// http://sourceforge.net/p/dotnetwikibot/svn/HEAD/tree/DebugBot.cs

		// Bot scripts repository is being created at
		// https://sourceforge.net/apps/mediawiki/dotnetwikibot/index.php?title=BSR
		// You are welcome to share your scripts.

		// And here you can find some basic usage examples:

		Site site = new Site("https://en.wikipedia.org", "YourBotLogin", "YourBotPassword");
		//Site site = new Site("http://mywikisite.com", "YourBotLogin", "YourBotPassword");
		//Site site = new Site("https://sourceforge.net/apps/mediawiki/YourProjectName/",
								//"YourSourceForgeLogin", "YourSourceForgePassword");

		site.ShowNamespaces();
		Page p = new Page(site, "Wikipedia:Sandbox");
		p.LoadWithMetadata();
		if (p.Exists())
			Console.WriteLine(p.text);
		p.SaveToFile("MyArticles\\file.txt");
		p.LoadFromFile("MyArticles\\file.txt");
		p.ResolveRedirect();
		Console.WriteLine(p.GetNamespace());
		p.text = "new text";
		site.defaultEditComment = "saving test";
		site.minorEditByDefault = true;
		p.Save();

		/**
		string[] arr = {"Art", "Poetry", "Cinematography", "Camera", "Image"};
		PageList pl = new PageList(site, arr);
		pl.LoadWithMetadata();
		pl.FillFromAllPages("Sw", 0, true, 100);
		pl.SaveTitlesToFile("MyArticles\\list.txt");
		pl.FillFromFile("MyArticles\\list.txt");
		pl.FillFromCategory("Category:Cinematography");
		pl.FillFromLinksToPage("Cinematography");
		pl.RemoveEmpty();
		pl.RemoveDisambigs();
		pl.ResolveRedirects();
		Console.WriteLine(pl[2].text);
		pl[1].text = "#REDIRECT [[Some Page]]";
		pl.FilterNamespaces(new int[] {0,3});
		pl.RemoveNamespaces(new int[] {2,4});
		pl.Clear();
		site.defaultEditComment = "my edit comment";
		site.minorEditByDefault = true;
		pl.Save();
		/**/
	}
开发者ID:DeinFreund,项目名称:Zero-K-Infrastructure,代码行数:56,代码来源:BotScript.cs

示例2: FillFromGoogleSearchResults

 /// <summary>Gets page titles for this PageList from Google search results.
 /// The function gets pages of all namespaces and it does not clear
 /// the existing PageList, so new pages will be added.</summary>
 /// <param name="searchStr">Words to search for. Use quotes to find exact phrases.</param>
 /// <param name="limit">Maximum number of page titles to get.</param>
 public void FillFromGoogleSearchResults(string searchStr, int limit)
 {
     if (string.IsNullOrEmpty(searchStr))
         throw new ArgumentNullException("searchStr");
     if (limit <= 0)
         throw new ArgumentOutOfRangeException("limit", Bot.Msg("Limit must be positive."));
     // TO DO: paging
     Uri res = new Uri("http://www.google.com/search?q=" + HttpUtility.UrlEncode(searchStr) +
         "+site:" + site.address.Substring(site.address.IndexOf("://") + 3) +
         "&num=" + limit.ToString());
     string src = Bot.GetWebResource(res, "");
     string relativeIndexPath = site.indexPath.Substring(site.indexPath.IndexOf('/', 10));
     string googleLinkToPagePattern = "<h3[^>]*><a href=\"(?<double_escape>/url\\?q=)?" +
         Regex.Escape(site.address).Replace("https:", "https?:") + "(?:" +
         (!string.IsNullOrEmpty(site.shortPath) ?
             Regex.Escape(site.shortPath) + "|" : "") +
         Regex.Escape(relativeIndexPath) + "\\?title=)?" + "(?<title>[^&\"]+)";
     Regex GoogleLinkToPageRegex = new Regex(googleLinkToPagePattern);
     MatchCollection matches = GoogleLinkToPageRegex.Matches(src);
     foreach (Match match in matches) {
         string title = HttpUtility.UrlDecode(match.Groups["title"].Value);
         if (title == "/") {
             if (site.messages == null)
                 site.LoadMediawikiMessages(true);
             string mainPageTitle = site.messages["mainpage"];
             Page p = new Page(site, mainPageTitle);
             p.ResolveRedirect();
             pages.Add(p);
         }
         else {
             if (!string.IsNullOrEmpty(match.Groups["double_escape"].Value))
                 title = HttpUtility.UrlDecode(title);
             pages.Add(new Page(site, title));
         }
     }
     Console.WriteLine(Bot.Msg("PageList filled with www.google.com search results."));
 }
开发者ID:KernelFreeze,项目名称:inteliBOT,代码行数:42,代码来源:DotNetWikiBot.cs


注:本文中的DotNetWikiBot.Page.ResolveRedirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。