如何使用C#代码查找并单击html文档(页面)中的href链接 [英] how to find and click on href link in a html document(page) using C# code

查看:101
本文介绍了如何使用C#代码查找并单击html文档(页面)中的href链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用c#代码找到一个href链接。

i am trying to find a href link using c# code.

推荐答案





看看这里:

http://stackoverflow.com/questions/6873762 / regx-find-href-value [ ^ ]

或者,您可以使用 Html Agility Pack 而不是正则表达式[ ^ ]:

Hi,

Have a look here:
http://stackoverflow.com/questions/6873762/regx-find-href-value[^]
Or, instead of a regular expression, you can use the Html Agility Pack[^]:
string htmlStr = @"<html><head><title>This is the title.</title></head>
                 <body><a href='page.html'>This is a link</a><br />
                 <a href='page2.html'>This is another link</a></body></html>";
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(htmlStr);
string[] urls = htmlDoc.DocumentNode.Descendants("a").Select(node => node.Attributes["href"].Value).ToArray();
foreach (string url in urls)
{
    Console.WriteLine(url);
}



希望这有帮助。


Hope this helps.


这篇关于如何使用C#代码查找并单击html文档(页面)中的href链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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