html代码可能如下所示
<html>
<body>
......
<textarea>
<div>
<a href="http://www.sohu.com">This is a hyper link </a>
</div>
</textarea>
......
</body>
</html>当我枚举链接时,
foreach (HtmlElement item in ieBrowser.document.Links)
{
var innerText = item.InnerText;
if ((string.IsNullOrEmpty(innerText)) || innerText.Length == 0) continue;
if (innerText.Contains(task.ShopName))
{
item.ScrollIntoView(true);
item.Focus();
item.SetAttribute("selected", "true");
item.SetAttribute("target", "_self");
item.InvokeMember("Click");
break;
}
}但是,But浏览器似乎无法识别textArea内部的链接。任何知道如何处理这件事的人。
发布于 2013-06-21 01:38:57
可以使用InnerHtml属性来提取文本区域上的内容。然后,可以使用HTMLAgilityPack查找链接并对其进行导航
HtmlElement textArea = webBrowser1.Document.All["textareaid"];
if (textArea != null)
{
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(textArea.InnerText);
foreach(HtmlAgilityPack.HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
{
HtmlAgilityPack.HtmlAttribute att = link["href"];
webBrowser1.Navigate(att.Value);
}
}https://stackoverflow.com/questions/17185817
复制相似问题