473,671 Members | 2,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retreving Html source code

What is the easiest way to retreive the html source from a web page?
Could you please provide an example?

Any and all help would be greatly appreciated

Aug 3 '06 #1
7 2776
Hi KelsMcKin,

Assuming you mean how to download a web page by code, the simplest way is
by using a WebClient.

using (WebClient wc = new WebClient())
{
byte[] data = wc.DownloadData ("http://www.downloadurl .com");
string html = Encoding.UTF8.G etString(data);
}

This assumes the data is UTF8-encoded.
On Thu, 03 Aug 2006 09:00:05 +0200, <Ke*******@gmai l.comwrote:
What is the easiest way to retreive the html source from a web page?
Could you please provide an example?

Any and all help would be greatly appreciated


--
Happy Coding!
Morten Wennevik [C# MVP]
Aug 3 '06 #2

Morten Wennevik wrote:
Hi KelsMcKin,

Assuming you mean how to download a web page by code, the simplest way is
by using a WebClient.

using (WebClient wc = new WebClient())
{
byte[] data = wc.DownloadData ("http://www.downloadurl .com");
string html = Encoding.UTF8.G etString(data);
}

This assumes the data is UTF8-encoded.
On Thu, 03 Aug 2006 09:00:05 +0200, <Ke*******@gmai l.comwrote:
What is the easiest way to retreive the html source from a web page?
Could you please provide an example?

Any and all help would be greatly appreciated

--
Happy Coding!
Morten Wennevik [C# MVP]
Thankyou so much, that was exactly what I was looking for

Aug 3 '06 #3
uh oh, I seem to be getting a cpanel message for every site, do you
have any idea why? I also get it if I use the url http://google.com
the code I get:

<HTML>
<HEAD>
<TITLE>cPanel </TITLE>
<link href="sys_cpane l/css/style.cssx" rel="stylesheet "
type="text/css">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=iso-8859-1">
<style>
body { font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px; background-color:#367E8E; scrollbar-base-color:
#005B70; scrollbar-arrow-color: #F3960B; scrollbar-DarkShadow-Color:
#000000; }
a { color:#ffffff; text-decoration:none }
</style>
</HEAD>
<BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0 ">
<table width="100%" height="100%" border="0" cellspacing="0"
cellpadding="0" >
<tr valign="top">
<td height="75" nowrap valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td width="10%"><a href="http://www.cpanel.net" ><img
src="sys_cpanel/images/index_01.gif" width="126" height="46"
alt="cPanel" border=0></a></td>
<td width="27%"><im g src="sys_cpanel/images/index_02.gif"
width="343" height="46"></td>
<td width="1%"
background="sys _cpanel/images/index_04.gif">< img
src="sys_cpanel/images/index_04.gif" width="43" height="46"></td>
<td width="62%" align="right"
background="sys _cpanel/images/index_04.gif">< img
src="sys_cpanel/images/index_03.gif" width="138" height="46"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<div style="color:ff 9900; font-weight:bold; font-size:24pt;
text-align:center">T here is no website configured at this
address.</div><br>
<br>
<div style="color:ff ffff">
You are seeing this page because there is nothing configured for the
site you have requested. If you think you are seeing this page in
error, please contact the site administrator or datacenter responsible
for this site.<br>
</div></td></tr>
<tr><td valign="bottom" >
<table width=100%>
<tr><td>
<div style="color:ff 9900; font-weight:bold">Ab out cPanel:</div><br>
<div style="color:ff ffff">cPanel is a leading provider of software for
the webhosting industry. If you would like to learn more about cPanel
please visit our website at <a class=josh
href="http://www.cpanel.net/">http://www.cpanel.net/</a>. Please be
advised that cPanel is not a webhosting company itself, and as such is
not responsible for content found elsewhere on this site.</div>
</tr>
</table>
</td>
</tr>
<tr>
<td height="10">
<table width="100%" border="0" cellspacing="0" cellpadding="0"
background="sys _cpanel/images/bbg.gif">
<tr align="center">
<td background="sys _cpanel/images/bbg.gif"><img
src="sys_cpanel/images/bbg.gif" width="179" height="22"></td>
<td background="sys _cpanel/images/bbg.gif"><img
src="sys_cpanel/images/bottom_label.gi f" width="382" height="22"></td>
<td background="sys _cpanel/images/bbg.gif"><img
src="sys_cpanel/images/bbg.gif" width="179" height="22"></td>
</tr>
</table>
</td>
</tr>
</table>
<!--- REVISION: 1.2 --->
</BODY>
</HTML>

Aug 3 '06 #4
Well,

Using this code I get

<html><head><me ta http-equiv="content-type" content="text/html;
charset=ISO-8859-1"><title>Googl e</title><style><!--
body,td,a,p,.h{ font-family:arial,sa ns-serif;}
..h{font-size: 20px;}
..q{color:#0000 cc;}
-->
</style>
<script>
<!--
function sf(){document.f .q.focus();}
// -->

and so on

I'm not familiar with cPanel site management tool, but I suspect it is
intercepting your network stream at some level.


On Thu, 03 Aug 2006 10:28:43 +0200, <Ke*******@gmai l.comwrote:
uh oh, I seem to be getting a cpanel message for every site, do you
have any idea why? I also get it if I use the url http://google.com
the code I get:

<HTML>
<HEAD>
<TITLE>cPanel </TITLE>
<link href="sys_cpane l/css/style.cssx" rel="stylesheet "
type="text/css">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=iso-8859-1">
<style>
body { font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px; background-color:#367E8E; scrollbar-base-color:
#005B70; scrollbar-arrow-color: #F3960B; scrollbar-DarkShadow-Color:
#000000; }
a { color:#ffffff; text-decoration:none }
</style>
</HEAD>
<BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0 ">
<table width="100%" height="100%" border="0" cellspacing="0"
cellpadding="0" >
<tr valign="top">
<td height="75" nowrap valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td width="10%"><a href="http://www.cpanel.net" ><img
src="sys_cpanel/images/index_01.gif" width="126" height="46"
alt="cPanel" border=0></a></td>
<td width="27%"><im g src="sys_cpanel/images/index_02.gif"
width="343" height="46"></td>
<td width="1%"
background="sys _cpanel/images/index_04.gif">< img
src="sys_cpanel/images/index_04.gif" width="43" height="46"></td>
<td width="62%" align="right"
background="sys _cpanel/images/index_04.gif">< img
src="sys_cpanel/images/index_03.gif" width="138" height="46"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<div style="color:ff 9900; font-weight:bold; font-size:24pt;
text-align:center">T here is no website configured at this
address.</div><br>
<br>
<div style="color:ff ffff">
You are seeing this page because there is nothing configured for the
site you have requested. If you think you are seeing this page in
error, please contact the site administrator or datacenter responsible
for this site.<br>
</div></td></tr>
<tr><td valign="bottom" >
<table width=100%>
<tr><td>
<div style="color:ff 9900; font-weight:bold">Ab out cPanel:</div><br>
<div style="color:ff ffff">cPanel is a leading provider of software for
the webhosting industry. If you would like to learn more about cPanel
please visit our website at <a class=josh
href="http://www.cpanel.net/">http://www.cpanel.net/</a>. Please be
advised that cPanel is not a webhosting company itself, and as such is
not responsible for content found elsewhere on this site.</div>
</tr>
</table>
</td>
</tr>
<tr>
<td height="10">
<table width="100%" border="0" cellspacing="0" cellpadding="0"
background="sys _cpanel/images/bbg.gif">
<tr align="center">
<td background="sys _cpanel/images/bbg.gif"><img
src="sys_cpanel/images/bbg.gif" width="179" height="22"></td>
<td background="sys _cpanel/images/bbg.gif"><img
src="sys_cpanel/images/bottom_label.gi f" width="382" height="22"></td>
<td background="sys _cpanel/images/bbg.gif"><img
src="sys_cpanel/images/bbg.gif" width="179" height="22"></td>
</tr>
</table>
</td>
</tr>
</table>
<!--- REVISION: 1.2 --->
</BODY>
</HTML>


--
Happy Coding!
Morten Wennevik [C# MVP]
Aug 3 '06 #5
How do you display the code?

The actual data have HTML in lower case.

Try saving the data directly to a file and use notepad to view it.

using (WebClient wc = new WebClient())
{
byte[] data = wc.DownloadData ("http://www.google.com" );

using(FileStrea m fs =
System.IO.File. Create(@"C:\Tes t.html"))
{
fs.Write(data, 0, data.Length);
}
}

--
Happy Coding!
Morten Wennevik [C# MVP]
Aug 3 '06 #6
It would be easier (and more correct) to use the WebClient's
DownloadString method, which uses the encoding specified in the
Encoding property to convert the resource to a string. Alternatively,
if you wish to write the data to a file without bothering with buffers
and FileStream objects, you could use the DownloadFile convenience
method.

Morten Wennevik wrote:
How do you display the code?

The actual data have HTML in lower case.

Try saving the data directly to a file and use notepad to view it.

using (WebClient wc = new WebClient())
{
byte[] data = wc.DownloadData ("http://www.google.com" );

using(FileStrea m fs =
System.IO.File. Create(@"C:\Tes t.html"))
{
fs.Write(data, 0, data.Length);
}
}

--
Happy Coding!
Morten Wennevik [C# MVP]
Aug 3 '06 #7
That may be easier, but in case of a html page encoded in a difference
format than the IIS claims, this would lead to a couple of more lines of
code. In either case you would need to parse the html to detect the
proper encoding, so in the end, downloading it as a most likely correct
encoding to begin with would be smarter.

Note though the DownloadString method is only supported in .Net 2.0, in
1.0 and 1.1 you are stuck with DownloadData or DownloadFile, though there
is always HttpWebRequest ...

On Thu, 03 Aug 2006 12:18:55 +0200, Jonathan <jo*******@gmai l.comwrote:
It would be easier (and more correct) to use the WebClient's
DownloadString method, which uses the encoding specified in the
Encoding property to convert the resource to a string. Alternatively,
if you wish to write the data to a file without bothering with buffers
and FileStream objects, you could use the DownloadFile convenience
method.

Morten Wennevik wrote:
>How do you display the code?

The actual data have HTML in lower case.

Try saving the data directly to a file and use notepad to view it.

using (WebClient wc = new WebClient())
{
byte[] data = wc.DownloadData ("http://www.google.com" );

using(FileStrea m fs =
System.IO.File .Create(@"C:\Te st.html"))
{
fs.Write(data, 0, data.Length);
}
}

--
Happy Coding!
Morten Wennevik [C# MVP]


--
Happy Coding!
Morten Wennevik [C# MVP]
Aug 3 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2015
by: asim | last post by:
Hi All i m transforming a simple XSL file on Server side using MSXML Parser ... and writting resultant HTML directly on browser .. is there any way to get this HTML in a variable ??? i seen the article on MSDN but it makes my page blank ... plz edit my code to make is work in this manner, if possible Thankx in advance Plz Help
11
3651
by: Patrick Van Esch | last post by:
Hello, I have the following problem of principle: in writing HTML pages containing ancient greek, there are two possibilities: one is to write the unicode characters directly (encoded as two bytes) into the HTML source, and save this source not as an ASCII text, but as a UNICODE text file (using 16 bits per character, also for the Western ASCII characters, which are usually encoded as Ox00XX with XX the ASCII code) ; or to write a pure...
2
1128
by: Amit Pandya | last post by:
Hi This is all using C# and i am new to it. I have a checkbox control that is added programmtically in the page_load event. Now on button click i want to retreive the checkbox control but i am not able to retreive. For retreving i am using FindControl method
78
4883
by: Robert Baer | last post by:
The homepage i have had up and seemingly working is: http://oil4lessllc.com/ However, the validator has so many complaints, and being so incompetent, i have no clue as to how to fix it all. Would the use of Dreamweaver be of great help?
2
4232
by: ste-m | last post by:
Hi there, I was wanting to calculate how long my web pages take to load, and to insert this time into my HTML source code (not visible from the browser, but only in source view) as a HTML comment. I've found a JavaScript that does this here: http://www.twohootssoftware.co.uk/code/loadtimejs.html <script language="javascript" type="text/javascript">
3
1695
tpgames
by: tpgames | last post by:
When I renamed the class file to Audiodriver.class and changed the link to Audiodriver.class, the game wouldn't load. I got this error java.lang.NoClassDefFoundError: Audiodriver (wrong name: Driver) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at sun.applet.AppletClassLoader.findClass(Unknown Source) at...
5
1342
by: hameeduddinasim | last post by:
Hi I am trying to take a particular value from dataset in to string kindly look at my code string image_url = dt.Rows.Table.Columns.ToString(); with the above code I am getting Column name in the string but i need the value of that perticular column
5
1619
by: GuyBowden | last post by:
Hi I'm trying to figure out why a certain server is rendering out strange html Sometimes it renders out html code to the browser window. See here: http://www.itsnotallwork.com/Picture%204.png The source code is absolutely fine - the page always validates. it just sometimes renders out some of the source (different bits each
0
8471
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8388
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8907
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8663
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7423
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5687
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4396
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2804
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.