View Full Version : Generated html into a variable

12-15-2003, 06:44 PM
Is there any way to get the asp page to load an external file's generated html into a variable?

i am trying to get stats from a site that isnt mine (its php btw) so i can display them in another way without all the crap inbetween so i really need to be able to get sections of the page into their own variables, but i assume that i should get the whole page's html into a variable and split it or something

Roy Sinclair
12-15-2003, 08:12 PM
With .Net you should be able to instantate a browser window (server side) navigate to a web site and then extract anything you want from the web page it brings up. I know I saw a post just last week about an XML object which could be used for this but I can't find that post right now.

Roy Sinclair
12-15-2003, 08:20 PM
Found it: http://www.codingforums.com/showthread.php?s=&threadid=29738&highlight=xmlhttp

12-16-2003, 06:52 PM
can you be a little more clear than that please, i do not want to refresh it or anything jsut get certain parts from the page

like if the page to get it from had a table containing this:

<td width="50%"><b><font size="1">Number of Penguins</font></b>&nbsp;</td>
<td width="50%"><b><font size="1">42</font></b>&nbsp;</td>
<td width="50%" bgcolor="#808080"><b><font size="1">Number of Hippos</font></b></td>
<td width="50%" bgcolor="#808080"><b><font size="1">57</font></b>&nbsp;</td>

how would i get the numbers of each animal into their own variables on the page that the asp is run from?
so i could write:

Penguins: <%=NoOfPenguins%><br>
Hippos: <%=NoOfHippos%>

and get an output of:

Penguins: 42
Hippos: 57

Roy Sinclair
12-16-2003, 07:53 PM
The example is in javascript and is also client side but there's nothing that keeps you from making it vbscript and running it server side. The biggest difference is that you wouldn't be running it every little bit, it'd only be run when your page is loaded but once it's run you'll have that web page loaded into an object where you can extract the values you want.

Untested code:

sub getWebPage(urlIn)
dim xmlhttp
set xmlhttp = server.createobject("Microsoft.XMLHTTP")
xmlhttp.Open("GET", urlIn, false)
if (xmlhttp.status = 200) then
... code to extract the data you want goes here
... code to handle a lack of response or an error goes here
end if
end sub

Use the XML DOM to find and extract the data: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmmthopenixmlhttprequest.asp

12-16-2003, 09:06 PM
just btw, i completely and utterly suck at vb

i could maby use that js on the other page (http://www.codingforums.com/showthread.php?threadid=27817) but i need to know what to replace

parent.window.frames[2].document.getElementById('chat-box').innerHTML = xmlhttp.responseText; with from my table html that i wrote earlier

btw, ty for all ur help in both my recent posts roy

Roy Sinclair
12-16-2003, 09:28 PM
If you're not good at VB, don't bother to learn it just code your ASP pages using javascript.

As for getting the data you want, the xmlhttp object can be thought of as the "window" object, just drill down to the objects you want just as if it were on a client browser because in fact that's what you're doing. The xmlhttp object is an instance of a browser which you created and told to load the referenced web page, then you can use the xmlhttp object to gain access to any of the objects in that browser window and therefore add them to your ASP page. Am I making any sense to you here?

12-16-2003, 10:54 PM
ok, v long thread and i still cant get it to work.. starting to get frustrated now...:mad:

if i make 2 pages:
the page with the original stats (originalStats.htm)

<title>Page With All the Original Stats on</title>
<td width="50%"><b><font size="1">Number of Penguins</font></b> </td>
<td width="50%"><b><font size="1">42</font></b> </td>
<td width="50%" bgcolor="#808080"><b><font size="1">Number of Hippos</font></b></td>
<td width="50%" bgcolor="#808080"><b><font size="1">57</font></b> </td>

and the page which should get variables from the other page and display them

<title>Page that should display 42 and 57</title>
function getMessages(){
var xmlhttp;
var responseText = '';
if (ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("GET", "originalStats.htm", false);
if (xmlhttp.status==200){
document.getElementById('noideawhatgoeshere').innerHTML = xmlhttp.responseText;

what do i need to change in the 2nd page and what am i doing wrong..now... see.. if you cna answer this as directly as possible, correct and test my code so that the 2nd page comes out how i want it, and tell me how to do it!

plz dont refer me to any manuals that dont help, tell me to go through a window object (thats just obvious) or anything like that... i dont care about the working, i just need a solution using the code i give in this post:D


12-17-2003, 08:58 PM
You can only use the XML DOM if the HTML page is valid XML (which it won't be unless it's actually XHTML).

Instead you should use regular expressions to parse the file and retrieve the parts you need.

12-17-2003, 09:31 PM
Instead you should use regular expressions to parse the file and retrieve the parts you need.

such as...

i know im stupid and everything but isnt that what i asked help with in the first place

12-17-2003, 11:16 PM
There's no need to be self-deprecating, get frustrated, or to take that attitude.


We are here to help you find a solution but judging from your previous posts in this thread (where you say you don't know VB and don't want to be directed to reference material), what you are asking for is a solution presented to you on a platter.

I can't speak for Roy, but I am not here to spend my time developing code for free for other people who show no willing to improve their own abilities. I am here to act as a facilitator, helping others learn new things and enhancing their understanding and competence with various aspects of the systems and languages that they work with, sometimes providing some demo code, and on very rare occasions getting someone 99% of the way there if it's particularly complicated or if someone really has been trying but hasn't quite grasped something.

Perhaps somebody else will do all the work for you, but I'm not going to...

12-18-2003, 07:38 AM
I'm not going to do all the work either..
If you don't want this link (http://www.4guysfromrolla.com/webtech/040600-1.shtml), then there's nothing more I can do to help you.

12-29-2003, 06:24 PM
ok m@rco, 1st of all.. nuts to you...now i feel a bit better..

well, all i wanted was my code to be corrected and ammended or some1 to tell me why it isnt working and what i need to do to fix it, glen is usualy a great help but if i knew how to do it i wouldnt be asking now would I?!?

12-29-2003, 06:35 PM
Originally posted by ghell
ok m@rco, 1st of all.. nuts to you...A mature response as expected. Glad you managed to sort it out yourself in the end.

12-29-2003, 07:45 PM
Originally posted by M@rco
A mature response as expected. Glad you managed to sort it out yourself in the end.
well, sarcasm isnt very mature so you cant comment on my maturity

anyway, just had to release my anger without punching anything/one or swearing

even so, you have assured me that what i ask CAN be done in asp on your site marcustucker.com in which you say:
"ASP scripts can manipulate data from databases, XML, pages on other web sites, user-entered information, uploaded files, and any other source you can think of" so, you do know how to do it, you are just not telling me...and yet you are apparently some kind of guru???

12-30-2003, 04:43 AM
Let's refrain from any further flaming and such in this thread, please. I understand your frustration, ghell, but probably the most important part of being a programmer is learning how to teach yourself. People usually give links for very good reasons... if they don't help then you're either doing something wrong or you need to speak up and say "Hey, these links aren't addressing my specific question!".

Have you tried them all out?

By the way, I was easily able to load another page using XMLHTTP and an http://www.w3schools.com/ example (which wasn't necessarily XHTML compliant) and parse it into very usable variables using regular expressions.

You might want to check that out as well.

12-31-2003, 07:51 PM
thanky you for understanding and helping me with my problem whammy

http://www.w3schools.com/xml/xml_http.asp helped a lot (http_obj.responseText is the variable i wanted isn't it?)

is ther any way of putting
<script type="text/vbscript">
function getPage()
set http_obj=createObject("Microsoft.XMLHTTP")
call http_obj.Open("GET","http://www.whatever.com",false)
call http_obj.Send()
a3.innerText = http_obj.responseText
end function

<body onload="getPage()">
into <%asp tags%> rather than a clienty type script block that loads with the onload of the body tag?

also, is ther any way of stopping it from showing this error in the picture attached in here

12-31-2003, 08:58 PM
Yeah, actually they have a server-side version there, I think...

If not I'll try to find one for you. Unfortunately today I have limited time, as I have to prepare for a New Year's Eve gig tonight with my band, AND it's my birthday. :)