Skip to main content

Microsoft Silverlight

Answered Question How can I get a remote page's HTML source?RSS Feed

(0)

dawmail333
dawmail333

Member

Member

0 points

4 Posts

How can I get a remote page's HTML source?

I'm after the source of a remote webpage, but every method I've tried to use has just timed out or not worked.

 How, using Silverlight 2.0, can I get the source of a remote (cross-domain) webpage?  I need to sift through it to gather some information.

Thanks in advance.

swildermuth
swildermuth

Star

Star

8320 points

1,546 Posts

Answered Question

Re: How can I get a remote page's HTML source?

You can only request the page if the other domain supoorts a cross domain access file (crossdomain.xml or the silverlight equivalent). Else, it won't return any HTML.

(If this has answered your question, "Mark as Answer")

Shawn Wildermuth
C# MVP, MCSD, Speaker and Author

Silverlight 3 Workshop
Miami, FL: Oct 12-14th
Portlant, OR: Dec 2-4th
Atlanta, GA: Dec 7-9th
http://silverlight-tour.com

Priyamjm
Priyamjm

Member

Member

234 points

32 Posts

Answered Question

Re: How can I get a remote page's HTML source?

swildermuth is correct.

Refer:

HTTP Communication and Security with Silverlight

http://msdn.microsoft.com/en-us/library/cc838250(VS.95).aspx

Downloading Content on Demand

http://msdn.microsoft.com/en-us/library/cc189021(VS.95).aspx

EX:

        void foo(string str_url)
        {
            WebClient oWebClient = new WebClient();
            oWebClient.OpenReadCompleted += new OpenReadCompletedEventHandler(oWebClient_OpenReadCompleted);
            oWebClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(oWebClient_DownloadProgressChanged);
            oWebClient.OpenReadAsync(new Uri(str_url), str_url);
        }

        void oWebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            string strProgress = e.ProgressPercentage.ToString() + "%";
        }

        void oWebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            if (null == e.Result)
            {
                //Some Error.
            }
            else if (e.Cancelled)
            {
                //Cancelled
            }
            else
            {
                Stream oStream = e.Result as Stream;
                //Use oStream
                //Your code here
            }
        }

 //Hope this will help you Smile

dawmail333
dawmail333

Member

Member

0 points

4 Posts

Re: How can I get a remote page's HTML source?

Seems like a bit of a no-brainer to me, there are so many ways around that.

 

Unless of course, it's because it is done client side and therefore can get information from pages they are authenticated on...  Is that what they call XSS?  I'm not sure.

swildermuth
swildermuth

Star

Star

8320 points

1,546 Posts

Re: Re: How can I get a remote page's HTML source?

You could do it server side (not using Silverlight) pretty easily, its the cross-site (XSS) support that isn't allowed.

(If this has answered your question, "Mark as Answer")

Shawn Wildermuth
C# MVP, MCSD, Speaker and Author

Silverlight 3 Workshop
Miami, FL: Oct 12-14th
Portlant, OR: Dec 2-4th
Atlanta, GA: Dec 7-9th
http://silverlight-tour.com
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities