XMLHTTP and javascript

L_P

New Member
Joined
Dec 3, 2011
Messages
3
I'm using XMLHTTP to grab the source from various pages so that I can extract links and information from them.

I've encountered a case where the information I need is buried inside the head block of the page, inside a script tag.

When I examine the string loaded into the xmlhttp's "response text" field, I'm finding that the script source has been filtered out. I.e. it's gotten the open and close script tags, but nothing between them.

Do I need to do something special with my XMLHTTP calls to get the javascript source to load? At the moment, I'm just doing the vanilla
Code:
      oXMLHTTP.Open "GET", theURL, False
      oXMLHTTP.send
to load in the page.


Looking at the page's source itself, I find that within the script tags, the code itself is enclosed between "<.!--" and "//-->" tags. (Without the period in that first tag, of course - that's just to get this parser not to strip out those codes in my forum message! :) )

Does this have something to do with it - and, if so, how do I get vba to go ahead and read the information wrapped within these tags?


thanks,
LP
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
It's difficult to help without knowing the URL.

The HTML comment tags "<.!--" and "//-->" is a standard way of hiding Javascript code from browsers which don't support Javascript or in which Javascript is disabled. I doubt whether these tags are causing the problem.

The code below correctly displays the embedded Javascript in the head section of this thread:
HTML:
<.script type="text/javascript">
<!--
var SESSIONURL = "";
var SECURITYTOKEN = "guest";
var IMGDIR_MISC = "images/misc";
var vb_disable_ajax = parseInt("0", 10);
// -->
<./script>
Code:
Public Sub XMLtest()

    Dim URL As String
    Dim XMLhttp As XMLhttp
    Dim i As Integer
    
    URL = "http://www.mrexcel.com/forum/showthread.php?t=597448"
        
    Set XMLhttp = New XMLhttp
    With XMLhttp
        .Open "GET", URL, False
        .send
        For i = 0 To 1
            MsgBox Mid(.responseText, i * 1023 + 1, 1023), Title:=i + 1
        Next
    End With
        
End Sub
As I said, I can't really help without the URL to see exactly what is happening.
 
Upvote 0
Re: XMLHTTP and javascript [SOLVED]

Thanks for the reply.

<snip>**snip**

Okay, I really *really* hate it when I struggle with something for several hours and then, in the course of finally breaking down and asking for help, stumble into the answer. To wit: I'm an idiot.

I was just proofreading the response and examples I'd typed in for you when it struck me:

The script tag for the page in question had the src="..." flag set.

I.e. the browser was loading in the script from a different page - but VBA's XMLHTTP parser (as was obvious the moment I asked myself the question) - was not. It doesn't "fill in" the source the way browsers do.

I pointed the url parameter to that source code page instead, and it worked like a charm.



Ah well, thanks for the reply that got me to realize this! Now that you've provided a good sounding board, I need to go find a good brick wall against which to bang my dense head... :)

-LP</snip>
 
Upvote 0
Re: XMLHTTP and javascript [SOLVED]

Thanks for the reply.

<snip>**snip**

Okay, I really *really* hate it when I struggle with something for several hours and then, in the course of finally breaking down and asking for help, stumble into the answer. To wit: I'm an idiot.

I was just proofreading the response and examples I'd typed in for you when it struck me:

The script tag for the page in question had the src="..." flag set.

I.e. the browser was loading in the script from a different page - but VBA's XMLHTTP parser (as was obvious the moment I asked myself the question) - was not. It doesn't "fill in" the source the way browsers do.

I pointed the url parameter to that source code page instead, and it worked like a charm.



Ah well, thanks for the reply that got me to realize this! Now that you've provided a good sounding board, I need to go find a good brick wall against which to bang my dense head... :)

-LP</snip>


Could you please share ...
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top