Skip to content Skip to sidebar Skip to footer

Reading Webpage Iframe Content In C#

I have been recently working in downloading webpage content using WebClient in C#. The DownloadString method of WebClient can not download the content from iframe. The short code

Solution 1:

You have to search for the iframe tag in the main page and then take the src attribute to download the page in the iframe

using (var client = new WebClient())
{
    string html = client.DownloadString("url");
    string src = ... //find iframe source with regexstring iframe = client.DownloadString(src);
}

For the regex you could use this Regular Expression to get the SRC of images in C#

Edit :

using (var client = new WebClient())
        {
            string html = client.DownloadString("http://multiprofits.co.uk/oddsmatcher.html");
            string src = Regex.Match(html, "<iframe.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value;
            Console.Write(client.DownloadString(src));
        }

You really get the iframe source with this code

Edit2 :

I have found your problem. It's a security issue from the site. Launch the iframe url in a new browser you will receive this message :

oddsmatcher is not permitted to run on this domain name [v2.oddsmatcher-data.co.uk/v2.oddsmatcher-data.co.uk] For more details please cotact support@oddsmonkey.com

So you must can't download directly the iframe source. You probably have to use WebBrowser or something like this

Post a Comment for "Reading Webpage Iframe Content In C#"