dbnewbie
asked on
Server.CreateObject("Msxml2.ServerXMLHTTP")
I'm trying to obtain the contents (XHTML, HTML, JavaScript, etc.) of a website. How do I get the source code of a particular webpage? The following gives me an error (object required) in VB6:
Set objHTTP = Server.CreateObject("Msxml 2.ServerXM LHTTP")
Please advise.
Set objHTTP = Server.CreateObject("Msxml
Please advise.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Doh! You're right, it is ASP. Lycaon, can you please complete the code to grab the site's source code and assign it to a string? Thanks.
ASKER
Never mind. Dumb request. Thanks.
dbnewbie,
Sorry I didn't add the entire code earlier, I was at work and didn't have my code with me. The following should work.
objHTTP.Open "GET", URL, False, "SomeUser", "SomePass"
' objHTTP.Open Method, URLToGet, Async, UserName, Password
' Method and URLToGet are REQUIRED. Async defaults to True, however, since you are not using a reference to the XML library, you do not have any events to work with. By setting Async to False, you cause the program to 'pause' until either the URL is retreived, or it encounters an error.
objHTTP.SetRequestHeader "Content-type", "text/html"
' Sets the expected content type, I believe
objHTTP.Send
' Sends the request.
rspText = objHTTP.ResponseText
' Places the retreived URL (usually text) into a variable
Set objHTTP = Nothing
'If you're not going to use the object again, set it to nothing
I've checked this code myself, and it works fine. As a side note, it appears to use IE's User-Agent header (sites like google refuse to send their pages to unknown user agents)
Another note, in my code it throws a fit unless the URL starts with http://
Lycaon
Sorry I didn't add the entire code earlier, I was at work and didn't have my code with me. The following should work.
objHTTP.Open "GET", URL, False, "SomeUser", "SomePass"
' objHTTP.Open Method, URLToGet, Async, UserName, Password
' Method and URLToGet are REQUIRED. Async defaults to True, however, since you are not using a reference to the XML library, you do not have any events to work with. By setting Async to False, you cause the program to 'pause' until either the URL is retreived, or it encounters an error.
objHTTP.SetRequestHeader "Content-type", "text/html"
' Sets the expected content type, I believe
objHTTP.Send
' Sends the request.
rspText = objHTTP.ResponseText
' Places the retreived URL (usually text) into a variable
Set objHTTP = Nothing
'If you're not going to use the object again, set it to nothing
I've checked this code myself, and it works fine. As a side note, it appears to use IE's User-Agent header (sites like google refuse to send their pages to unknown user agents)
Another note, in my code it throws a fit unless the URL starts with http://
Lycaon
1.add a 'Microsoft Internet Transfer Control' to your form and...
Dim sSrc As String
sSrc = Inet1.OpenURL("cnn.com")
Text1.Text = sSrc