Click here to Skip to main content
Licence 
First Posted 27 Mar 2001
Views 232,005
Downloads 2,591
Bookmarked 36 times

Get HTML Source of any URL

By | 3 Apr 2001 | Article
This articles shows how to get HTML source of a URL, even if the URL uses tricks to prevent you from viewing the source

Introduction

Some web sites don't let you view the source code by disabling the right mouse key. Some other web sites don't display top level menus, so you can not view source using "View + Source" menu option.

How to display the code

So, how do you display the code, if a site uses one of the above method to prevent you from seeing the source code. The sample ASP application uses Microsoft XMLHttp object to get a URL's source code. It just makes a synchronous HTTP Get request and displays the response in a textarea.

Installation Notes

Copy the ASP file to the root directory (typically, inetpub/wwwroot). You must run either a Personal Web Server on your machine or have access to a web server that runs IIS.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Dhandapani Ammasai



India India

Member

Dhandapani Ammasai(Dan in short) is a software delivery manager at a top tier IT company in India.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralCode in ASP.NET Pinmemberarwany2@yahoo.com22:11 19 Sep '07  
QuestionGetSourceCode.asp is giving error PinmemberJaks M0:18 23 Dec '06  
GeneralPls Help me Emergently PinmemberAlexDa0:20 13 Mar '06  
GeneralWindow to fill the screen PinsussAnonymous0:59 25 Jan '05  
GeneralEasy Source Code View PinsussRajaRavipati23:57 31 Aug '04  
GeneralRe: Easy Source Code View Pinmemberrichardhennessy4:53 10 Feb '05  
GeneralEasy Source Code View PinsussRajaRavipati23:48 31 Aug '04  
GeneralWorking perfectly for one url. I need to do it for multiple urls. PinsussAnonymous4:39 16 May '03  
GeneralWorking perfectly for one url. I need to do it for multiple urls. PinsussAnonymous4:39 16 May '03  
GeneralWas lookin for something like this last week PinmemberIvel11:47 13 Mar '03  
Generalview-source protocol Pinmember.S.Rod.18:03 29 Oct '02  
GeneralGetSourceCode.asp is giving error Pinsussvikas kumar17:02 29 Oct '02  
Generalthelp me please PinsussAnonymous22:09 10 Jul '02  
GeneralProblem with this method. PinmemberSantiago Suarez14:22 9 Jun '02  
GeneralThis always works. PinmemberMike Whitenton8:48 7 Feb '02  
GeneralRe: This always works. PinmemberPhilip Patrick8:22 18 Mar '02  
GeneralRe: This always works. PinmemberAnonymous6:39 6 May '02  
GeneralRe: This always works. PinsussSmashfist10:28 3 Nov '04  
GeneralBin to AscII PinmemberBenny A11:44 29 Jan '02  
IIS doesn't support Unicode files but ADO does...
before having an ASCII file that your server will then be able to read convert the send bin data into a unicode data.
Great tip from: http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=128
Use local recordset to do that:
 
Response.Write BinToText(GetHTMLBin("http://Your URL goes here.whatever"), 35000)
 
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Function to return binary data
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function GetHTMLBin(strURL)
Dim objXMLHTTP, strReturn
Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
 
objXMLHTTP.Open "GET", strURL, False
objXMLHTTP.Send Cstr(Rnd())
 
GetHTMLBin = objXMLHTTP.responseBody
Set objXMLHTTP = Nothing
End Function
 

' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Function to convert binary data to text
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function BinToText(varBinData, intDataSizeInBytes) ' as String
Const adFldLong = &H00000080
Const adVarChar = 200
Set objRS = Server.CreateObject("ADODB.Recordset")
 
objRS.Fields.Append "txt", adVarChar, intDataSizeInBytes, adFldLong
objRS.Open
 
objRS.AddNew
objRS.Fields("txt").AppendChunk varBinData
BinToText = objRS("txt").Value
 
objRS.Close
Set objRS = Nothing
End Function

GeneralViewing Source PinmemberJason Hooper10:58 29 Jan '02  
GeneralGreat Com Great Tip PinmemberBenny A10:14 29 Jan '02  
GeneralProblem using "GetSourceCode.asp" PinmemberBrenda Yip17:59 14 Jan '02  
GeneralRe: Problem using "GetSourceCode.asp" PinmemberAnonymous22:20 11 Feb '02  
QuestionProblem using GetHTML after a while? PinmemberAnders1:04 21 Oct '01  
AnswerRe: Problem using GetHTML after a while? PinmemberLuna7:29 6 Nov '01  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120528.1 | Last Updated 4 Apr 2001
Article Copyright 2001 by Dhandapani Ammasai
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid