Click here to Skip to main content
15,935,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to collect information about a list of web pages using JScript in Windows Scripting Host. And to do that, I need to get the source of each HTML page and parse it.

What I need is, create some kind of HTML DOM object using the responseText/responseXML and use the familiar getElementById, and getElementsByTagNames functions on that HTML DOM. How do I do that?

I am using the following JScript and running it using Windows Scripting Host V5.8.

JavaScript
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var xmldom = xmlhttp.responseXML;
            
            if (xmldom.parsed) {
                var imgs = xmldom.getElementsByTagName('img');
                WScript.Echo("imgs: " + imgs + " " + imgs.length);
            }
        }
    }
}

xmlhttp.open("GET", "http://www.example.com/somepage.php", false);
xmlhttp.send();


And I am getting the following output.

imgs:  0


I have been searching the whole night yesterday and had no luck!
Posted
Comments
krumia 17-Jun-12 0:24am    
P.S.: Am I doing something stupid here? Could you guys suggest another approach other than JScript?
Sandeep Mewara 17-Jun-12 2:04am    
Did you debug and see what was response xml?
krumia 17-Jun-12 2:34am    
I looked at responseText it contains the HTML source. No problem their.
I tried to print the responseXML attribute to console, and it produces an empty line.
I am not using any IDE, just the notepad. So I don't know any other way of debugging.

1 solution

Well, you got back a HTML and not a XML and that is the reason why you are having such experience.

Have a look here: HTML to DOM[^]

Following discussion would also help: http://forums.mozillazine.org/viewtopic.php?f=19&t=1594275[^]
 
Share this answer
 
Comments
Manas Bhardwaj 18-Jun-12 5:41am    
Correct +5!
Sandeep Mewara 18-Jun-12 11:27am    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900