-
Problem Looping through script and ignore invalid urls.
Hi
I am working on a project that would go out and retrieve specific content from websites through the req.open("get",url,false) method. The script loops through an array of stock symbols and retrieves information from the url specified.
So far the script works great, it does everything I want it to do, except one thing
Since I am going to be working with a lot of stock symbols there will be some symbols the website does not have on their database and it seems that every time I come across a symbol that is not on their database the script just stops.
below is the script I am working on and if you look at my array you will notice a stock symbol named "aa.p", even though it is a valid symbol the website from which I am retrieving information from does not contain that symbol.
I am not sure where the problem is, you may first want to remove the symbol "aa.p" and run the script to see it work and then add the symbol "aa.p" to the array and you will see the issue I am facing.
Here is the below code.
var req = new ActiveXObject("Microsoft.XMLHTTP");
var mysymbol = new Array()
mysymbol[0] = "goog";
mysymbol[1] = "diod";
mysymbol[2] = "aa.p";
mysymbol[3] = "hal";
mysymbol[4] = "ppdi";
function getdata()
{
for (var i = 0; i < mysymbol.length; i++)
{
req.open("GET", "http://quote.barchart.com/texpert.asp?sym=" + mysymbol, false);
handleResponse(i)
}
}
function handleResponse(i)
{
req.send(null);
if(req.readyState == 4)
{
if(req.status == 200)
{
document.write(mysymbol + " " + req.responseText.length + " valid <p>")
}
else
{
document.write(mysymbol + " invalid <p>")
}
}
}
-
-
Sorry some for some reason the "i" was never pasted in my code here is the code with mysymbol[i]
var req = new ActiveXObject("Microsoft.XMLHTTP");
var mysymbol = new Array()
mysymbol[0] = "goog";
mysymbol[1] = "diod";
mysymbol[2] = "aapl";
mysymbol[3] = "aa.p";
mysymbol[4] = "ppdi";
function getdata()
{
for (var i = 0; i < mysymbol.length; i++)
{
req.open("GET", "http://quote.barchart.com/texpert.asp?sym=" + mysymbol[i], false);
handleResponse(i)
}
}
function handleResponse(i)
{
req.send(null);
if(req.readyState == 4)
{
if(req.status == 200)
{
document.write(mysymbol[i] + " " + req.responseText.length + " valid <p>")
}
else
{
document.write(mysymbol[i] + " invalid <p>")
}
}
}
-
-
when you send a request using "aa.p", the site still returns something. Try the following link.
http://quote.barchart.com/texpert.asp?sym=aa.p
That's why, you can't really say that this URL is invalid. If the site would return a different status code, for example, 300 or 404, then you could place condition for this. So, you would have to come with something else
Also, I doubt that the site is only searching for the symbols, when you send the request like that. I tried the following with my login name as the stock symbol and guess what they show you.
http://www2.barchart.com/lookup.asp?sym=pman
You might have to find out if that site has any other way to search through "Symbol" fields ONLY in their database.
By the way, your script will only work in IE. Other browsers know nothing about ActiveX
-
-
Thanks pman
I actually knew of another way to access the site and I tried that, it seems to be working now thanks
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks