内部链接提取器代码 [英] internal Link extractor code
本文介绍了内部链接提取器代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要链接提取器的C#代码,例如
如果我以www.yahoo.com的身份输入
那么我的输出应该是www.yahoo.com上的所有内部消息,都应保存在一个文本文件中.
我知道我必须使用LinksExtractor类,但没有得到怎么做
例如ip:www.yahoo.com
o/p:
www.yahoo.com/sports
www.yahoo.com/Business
I want c# code for link extractor,like
if i give input as a www.yahoo.com
then my output should be all intranal lnks on www.yahoo.com,which should save in one text file.
i know i have to use LinksExtractor class but not getting how to do
e.g. ip:www.yahoo.com
o/p:
www.yahoo.com/sports
www.yahoo.com/Business
推荐答案
开始吧:)
创建公共列表链接:
Let''s start :)
Create a public List links:
List<string> links = new List<string>();</string></string>
private void FindLinks(string url)
{
links.Clear();
WebBrowser webBrowser1 = new WebBrowser();
webBrowser1.Navigate(url);
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (((WebBrowser)sender).Document != null)
{
HtmlElementCollection col = ((WebBrowser)sender).Document.GetElementsByTagName("a");
foreach (HtmlElement elem in col)
{
if (elem.GetAttribute("href").StartsWith("http://"))
links.Add(elem.GetAttribute("href"));
}
}
}
调用函数使用:
Call function using:
FindLinks(@"http://www.google.gr/");
所有链接都将在列表链接中
All links will be in the List links
这篇关于内部链接提取器代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文