开发者

Reading links in header using WebKit.NET

开发者 https://www.devze.com 2023-02-15 03:37 出处:网络
I am trying to figure out how to read header links using C#.NET. I want to get the edit link from Browser1 and put it in browser 2. My problem is that I can\'t figure out how to get at attributes, or

I am trying to figure out how to read header links using C#.NET. I want to get the edit link from Browser1 and put it in browser 2. My problem is that I can't figure out how to get at attributes, or even the link tags for that matter. Below is what I have now.

using System.XML.Linq;
...
string source = webKitBrowser1.DocumentText.ToString();
XDocument doc = new XDocument(XDocument.Parse(source));
webKitBrowser2.Navigate(doc.Element("link").Attribute("href").Value.ToString());

This would work except that xml is different 开发者_如何学Pythonthan html, and right off the bat, it says that it was expecting "doctype" to be uppercase.


I finally figured it out, so I will post it for anyone who has the same question.

string site = webKitBrowser1.Url.Scheme + "://" + webKitBrowser1.Url.Authority;
WebKit.DOM.Document doc = webKitBrowser1.Document;
WebKit.DOM.NodeList links = doc.GetElementsByTagName("link");
WebKit.DOM.Element link;
string editlink = "none";
foreach (var item in links)
{
    link = (WebKit.DOM.Element)item;
    if (link.Attributes["rel"].NodeValue == "edit") { editlink = link.Attributes["href"].NodeValue; }
}
if (editlink != "none") { webKitBrowser2.Navigate(site + editlink); }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号