"Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event."
The WebClient class provides some common methods for sending data to and receiving data from a resource identified by a URL.
As you description and replies above, you just need to retrieve data from one URL, please check this reference below about WebClient which shows several methods to retrieve data from URL
The following table describesWebClientmethods for downloading data from a resource.
vijaycool
Member
285 Points
290 Posts
Get html of a given link
May 07, 2012 06:45 AM|LINK
Hi all,
I have been trying to get html of a web page having images, but not getting.
How to do it????
Thanks in advance
vijay
tusharrs
Contributor
3230 Points
668 Posts
Re: Get html of a given link
May 07, 2012 06:48 AM|LINK
not understand your query
but i guess you want
1) in the brower select save page as option
2) or you wnat to see the page source so right click on the browser and select view page source option
( Mark as Answer if it helps you out )
View my Blog
Bimalvv
Contributor
2346 Points
478 Posts
Re: Get html of a given link
May 07, 2012 06:53 AM|LINK
You WebClient, which will help to download the html
protected void Page_Load(object sender, EventArgs e) { using (WebClient client = new WebClient()) { client.DownloadStringCompleted += client_DownloadStringCompleted; client.DownloadStringAsync(new Uri("Your url")); } } void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { string html = e.Result; }Bimal
vijaycool
Member
285 Points
290 Posts
Re: Get html of a given link
May 07, 2012 07:17 AM|LINK
Hi Bimal,
Its throwing an exception
"Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event."
Bimalvv
Contributor
2346 Points
478 Posts
Re: Get html of a given link
May 07, 2012 08:02 AM|LINK
Two ways
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" Async="true" %>or
2. Use sync method call like
string html = null; using (WebClient client = new WebClient()) { html = client.DownloadString(new Uri("Your url")); }Bimal
sriramabi
Contributor
4351 Points
1277 Posts
Re: Get html of a given link
May 07, 2012 08:16 AM|LINK
hai
pls ref this
http://www.dotnetperls.com/scraping-html
http://stackoverflow.com/questions/2248411/get-all-links-on-html-page
http://stackoverflow.com/questions/7898850/how-to-find-a-link-in-html-document-c
thank u
Mamba Dai - ...
All-Star
23531 Points
2683 Posts
Microsoft
Re: Get html of a given link
May 14, 2012 06:09 AM|LINK
Hi,
The WebClient class provides some common methods for sending data to and receiving data from a resource identified by a URL.
As you description and replies above, you just need to retrieve data from one URL, please check this reference below about WebClient which shows several methods to retrieve data from URL
The following table describes WebClient methods for downloading data from a resource.
<div style="text-align: left; widows: 2; text-transform: none; text-indent: 0px; letter-spacing: normal; font: bold 13px 'Segoe UI', Verdana, Arial; white-space: normal; orphans: 2; height: 20px !important; color: #3f529c; clear: both !important; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="caption" xmlns="http://www.w3.org/1999/xhtml"></div> <div style="text-align: left; widows: 2; text-transform: none; text-indent: 0px; letter-spacing: normal; font: 13px 'Segoe UI', Verdana, Arial; white-space: normal; orphans: 2; color: #000000; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="tableSection" xmlns="http://www.w3.org/1999/xhtml">Method
Description
OpenRead
Returns the data from a resource as a Stream.
OpenReadAsync
Returns the data from a resource, without blocking the calling thread.
DownloadData
Downloads data from a resource and returns a Byte array.
DownloadDataAsync
Downloads data from a resource and returns a Byte array, without blocking the calling thread.
DownloadFile
Downloads data from a resource to a local file.
DownloadFileAsync
Downloads data from a resource to a local file, without blocking the calling thread.
DownloadString
Downloads a String from a resource and returns a String.
DownloadStringAsync
Downloads a String from a resource, without blocking the calling thread.
Apart from using WebClient, you also can try using HmtlAgilityPack which is a html parser/crawler
http://htmlagilitypack.codeplex.com/
Feedback to us
Develop and promote your apps in Windows Store
Primillo
Star
8723 Points
1677 Posts
Re: Get html of a given link
May 14, 2012 06:44 AM|LINK
Hi
To read the whole page:
private string HttpContent( string url ) { WebRequest objRequest= System.Net.HttpWebRequest.Create(url); StreamReader sr = new StreamReader( objRequest.GetResponse().GetResponseStream() ); string result = sr.ReadToEnd(); sr.Close(); return result; }Primillo
http://www.facebook.com/programandopuntonet