.NET中的URL解析器 [英] URL Parser in .NET

查看:234
本文介绍了.NET中的URL解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Team,

我需要在.net框架中实现url解析器。当输入网址时,应用程序应显示给定网址中的图像数量,单词数量和最常用的单词。

I need to implement the url parser in .net framework. when a url is inputted, the application should display the number of images , count of words and most used words in the given url.

请提供最好的解决方案或任何插件。

Please provide the best possible solution or any plug in available.

请记住在答案上单击标记为答案,如果它可以帮助您

Please remember to click Mark as Answer on the answer if it helps you

推荐答案

首先,使用
System.Net.WebClient
.DownloadFile()或.DownloadString下载内容。

First, you use System.Net.WebClient.DownloadFile() or .DownloadString to download the content.

To计算图像的数量,计算"< img"的出现次数。

RegEx.Matches()。

To count the number of images, count the occurance of "<img" with RegEx.Matches().

要计算字符数,请在''上使用String.Split()和RemoveEmptyEntries。您可能希望添加一些String.Replace()以替换某些符号  with space(例如,",","to""")以确保它被正确地标记化。然后 返回
结果数组的长度。

To count the number of characters, use String.Split() on ' ' with RemoveEmptyEntries. You may want to add some String.Replace() to replace certain symbol with space (say, "," to " ") to ensure it's properly tokenized. And then return the length of resulting array.

要找到最常用的单词,我将循环使用之前生成的标记化数组,并使用Dictionary< string,int>存储每个单词的出现。最后使用.Select(x => x.Value).Max()来获取最大出现次数,并输出
字典中的所有单词,其匹配计数如下:

To found the most used word, I'd loop against the previously generated tokenized array, and use a Dictionary<string, int> to store occurance of each word. Finally use .Select(x => x.Value).Max() to get the max occurance count, and output all word within the Dictionary with the matching count with something like:

int maxcnt = result.Select(x => x.Value).Max(); foreach (string word in result.Where(x => x.Value == maxcnt).Select(y => y.Key)) { Console.WriteLine(word); } //or the following to store the result directly in array: string[] maxOccWords = result.Where(x => x.Value == maxcnt).Select(y => y.Key).ToArray();

替换Console.WriteLine(),带有用于存储结果的语句。

Replace Console.WriteLine() with statement to store the outcome.


这篇关于.NET中的URL解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆