[英]How to extract & show data informations of web page
i have a problem & i need some help please i want to creat a program [C#] to extract a data informations from a website & show the informations on my program i'm not good with this methode & i need a exemple (to learn it) so for exemple i have this website:www.whatismyip.com i want to extract just for exemple the informations of country (Country: USA) from the webpage:我有一个问题,我需要一些帮助,我想创建一个程序 [C#] 来从网站中提取数据信息并显示我的程序中的信息我不擅长这种方法,我需要一个例子(学习它)所以例如我有这个网站:www.whatismyip.com 我想从网页中提取例如国家(国家:美国)的信息:
<div class="country">Country:</div> <div class="the-country">USA
& show it in my program [C#]like this (Country: USA) i very need a help to resolve this problem please if some one know a methode or any think please &在我的程序中显示它 [C#] 像这样(国家:美国)如果有人知道方法或任何想法,我非常需要帮助来解决这个问题
I did something similar, but it was for checking current minecraft version.我做了类似的事情,但它是为了检查当前的我的世界版本。 I used Html Agility Pack .
我使用了Html Agility Pack 。 It will allow you to read in the code and sort for whatever information you need.
它将允许您阅读代码并根据您需要的任何信息进行排序。 Here's the code I used for it.
这是我用于它的代码。
Regex Regex = new Regex("[^0-9.]");
HtmlWeb client = new HtmlWeb();
//Check Server version
try
{
HtmlAgilityPack.HtmlDocument doc = client.Load("https://minecraft.net/download");
HtmlNodeCollection Nodes = doc.DocumentNode.SelectNodes("//p//a[@href]");
ServerVersion = Regex.Replace(Nodes[4].InnerText, String.Empty).Remove(0, 1).TrimEnd('.');
BStripServerVersion.Text = ServerVersion + " |";
FileName = (Nodes[6].InnerText);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
You will probably have to fix some areas and search for div classes.您可能需要修复某些区域并搜索 div 类。 My code reads in all paragraph/ahref statements in the webpage, and then stores it in a array.
我的代码读取网页中的所有段落/ahref 语句,然后将其存储在一个数组中。 Afterwards - I had to manually go through till I found the right one I wanted.
之后 - 我不得不手动通过,直到找到我想要的正确的。 I believe this will would for you too.
我相信这对你也会有帮助。 My code may/may not be efficient but it gives you a idea.
我的代码可能/可能效率不高,但它给了你一个想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.