Can I Read Iframe Through Webclient (i Want The Outer Html)? July 25, 2024 Post a Comment Well my program is reading a web target that somewhere in the body there is the iframe that i want to read. My html source ... Solution 1: After getting the source of the site, you can use HtmlAgilityPack to get the url of the iframeHtmlAgilityPack.HtmlDocumentdoc=newHtmlAgilityPack.HtmlDocument(); doc.LoadHtml(html); varsrc= doc.DocumentNode.SelectSingleNode("//iframe") .Attributes["src"].Value; Copythen make a second call to get_url_sourceSolution 2: Parse your source using HTML Agility Pack and then:List<String> iframeSource = newList<String>(); HtmlDocument doc = new HtmlDocument(); doc.Load(url); foreach (HtmlNode node in doc.DocumentElement.SelectNodes("//iframe")) iframeSource.Add(get_url_source(mainiFrame.Attributes["src"])); CopyIf you are targeting a single iframe, try to identify it using ID attribute or something else so you can only retrieve one source:String iframeSource; HtmlDocument doc = new HtmlDocument(); doc.Load(url); foreach (HtmlNode node in doc.DocumentElement.SelectNodes("//iframe")) { // Just an example for check, but you could use different approaches...if (node.Attributes["id"].Value == 'targetframe') iframeSource = get_url_source(node.Attributes["src"].Value); } CopySolution 3: Well i found the answer after some search and this is what i wantedwebBrowser1.Url = new Uri("http://www.mysite.com/"); while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents(); string InnerSource = webBrowser1.Document.Body.InnerHtml; //You can use here OuterHtml too.Copy Share Post a Comment for "Can I Read Iframe Through Webclient (i Want The Outer Html)?"
Post a Comment for "Can I Read Iframe Through Webclient (i Want The Outer Html)?"