Welcome to WebmasterWorld Guest from 54.145.166.247

Forum Moderators: httpwebwitch

Message Too Old, No Replies

Scraping data from an RSS feed

help needed

   
4:44 pm on Oct 9, 2008 (gmt 0)

10+ Year Member



hi there I have a website that calls an rss.xml to change the currency from us to canadian if they choose...I am not a programmer and have no idea how to fix....Iam providing the code below if anyone can give me some insight I would greatly appreciate it...if you need the full url for the site let me know thanks again

function to get currency exchange rate from RSS feed
function getCurrency( sCurrency )

sBasePrice = "USD"
//sBasePrice = "CAD"

Response.Charset = "UTF-8"

Dim objXML
Dim objItemList
Dim objItem
Dim nCurrency

Set objXML = Server.CreateObject( "MSXML2.FreeThreadedDOMDocument" )
objXML.async = False

objXML.setProperty "ServerHTTPRequest", True
objXML.Load( "http://currencysource.com/RSS/" & sBasePrice & ".xml" )

' set currency exchange rate to 1 CAD = 1 USD if error with RSS feed
nCurrency = 1

' no errors
If objXML.parseError.errorCode = 0 Then

Set objItemList = objXML.getElementsByTagName( "item" )
Set objXML = Nothing

'RSS Feed childNodes: 0=title, 1=link, 2=description, 3=pubdate
For Each objItem In objItemList

' check if current item is USD
' 1 CAD = USD (0.861966)
if Mid( objItem.childNodes( 0 ).text, 1, 11 ) = "1 " & sBasePrice & " = " & sCurrency then
nCurrency = Left( Mid( objItem.childNodes( 0 ).text, 14 ), Len( Mid( objItem.childNodes( 0 ).text, 14 ) ) - 1 )
exit for
end if

Next

Set objItemList = Nothing

End If

getCurrency = nCurrency

end function

4:58 pm on Oct 9, 2008 (gmt 0)

WebmasterWorld Senior Member demaestro is a WebmasterWorld Top Contributor of All Time 10+ Year Member



What are you trying to fix?
5:01 pm on Oct 9, 2008 (gmt 0)

10+ Year Member



when i choose canadian on the site it does not change the price just stays the same as it displayed in US funds
8:11 pm on Oct 9, 2008 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



for the benefit of the group
river_east is scraping data out of an XML node that looks like this:
<title>1 USD = CAD (1.124512)</title>

* * *

so. what is returned from getCurrency("CAD") ?

I don't see anything glaringly wrong with the function. Nothing obvious anyways.

debugging tip: inject little debugging one-liner commands into your script and echo out variables to see what their values are.

for instance, echo out "objItem.childNodes( 0 ).text" and see if it is what you expect.
Then echo out "Mid( objItem.childNodes( 0 ).text, 1, 11 )". Take the code in little chunks and verify that it's doing everything right from top to bottom.

It may be something as simple as a bad boundary limit in the Mid() or Left() string functions.

Also, you may consider using a regular expression to extract the data instead of awkwardly nested substring functions.

2:08 pm on Oct 10, 2008 (gmt 0)

10+ Year Member



it appears to be an issue with [currencysource.com...] they must have changed the path Im not sure the new path?
5:01 pm on Oct 10, 2008 (gmt 0)

WebmasterWorld Senior Member demaestro is a WebmasterWorld Top Contributor of All Time 10+ Year Member



That URL gives "Directory Listing Denied" message... which leads me to beleive it hasn't move but now requires some sort of auth. It could be it limits people by referrer or IP I would contact them and inquire.
6:18 pm on Oct 10, 2008 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



these two lines say it all:

sBasePrice = "USD" 
objXML.Load( "http://currencysource.com/RSS/" & sBasePrice & ".xml" )

thus the URL being requested is actually
[currencysource.com...]

really I think the problem is something subtle in the way the data is being parsed. Or maybe it's a syntax error somewhere? I don't have the right machinery running to try your code sample out myself, and I'm very rusty on my VBScript syntax.

Debugging is a tough job, and it's a skill that takes practice. Start by "tracing [en.wikipedia.org]" values to see what they are during the execution of the code. Fixing this function should take a few minutes, not several days.

Tracing is probably the most important debugging technique you must learn, and it's much simpler than, say, bug discovery by systematic amputation, or dissecting the call stack.

The key here is to learn some debugging techniques so you can find out what the problem is. I'm guessing that once you figure out the problem, the solution will be immediately obvious.

6:34 pm on Oct 10, 2008 (gmt 0)

10+ Year Member



great thanks for all your insight I really appriciate it...i do some testing or at least try and I'll let you know