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
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
5,999
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.
 

L_P

New Member
Joined
Dec 3, 2011
Messages
3
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>
 

tomcatonnet99

Board Regular
Joined
Jan 30, 2011
Messages
73
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 ...
 

Forum statistics

Threads
1,082,151
Messages
5,363,430
Members
400,736
Latest member
Aida

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top