Page 1 of 1

put URL strange behavior

Posted: Mon Feb 10, 2014 3:18 pm
by snm
I have problem with put Url sequence of script code:
When my script is:

Code: Select all

put url "http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html" into msg
it puts expected html page source into msg box.

Also if my script is:

Code: Select all

put url "http://www.nbp.pl/kursy/xml/c027z140210.xml" into msg
it's working, I have xml text in msg box.

But if I have both:

Code: Select all

put url "http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html" into msg
put url "http://www.nbp.pl/kursy/xml/c027z140210.xml" into msg
the msg box is empty, there is no xml text.

Is it possible I'm doing something wrong?

Marek

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 3:39 pm
by Klaus
HI Marek,

just tested here and I get "error" in the dialog:
...
put url "http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html" into msg
put url "http://www.nbp.pl/kursy/xml/c027z140210.xml" into msg
answer the result
## -> error
...
But I have no idea what error is happening.
Even adding "wait 5 secs" between the calls does not help!?


Best

Klaus

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 3:57 pm
by snm
No, even more then few minutes of wait doesn't help. First put url statement finishes loading, then I parse next url from downloaded html code. I have correct parsed url before second put url statement. I used "static" urls as text in put url statements to check why is this error, and to send short code making problem only.

Marek

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 4:05 pm
by bn
Hi Marek,

I also see what you describe. First I thought it was the bank blocking access to xml if accessed in too short intervalls.

this works for me

Code: Select all

   put url "http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html" into msg
   put url "http://www.nbp.pl/kursy/xml/c027z140210.xml" into msg
   put url "http://www.nbp.pl/kursy/xml/c027z140210.xml" into msg
I just don't know why.

Maybe someone has an idea?

Kind regards
Bernd

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 4:55 pm
by snm
Hi Bernd,

Thanks a lot for next help. Your solution is working perfect.
I have also no idea what could be the reason.

Marek

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 5:00 pm
by Thierry
snm wrote:I have also no idea what could be the reason.
Marek
What's happening if you do something like that:

put url ... into msg1
put url .... into msg2
put msg1 && msg2

Thierry

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 5:17 pm
by snm
msg2 is empty if urls are in sequence shown as problematic in my first post.

Marek

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 5:37 pm
by Thierry
Umm, did the same test as Bernd with success...

No idea :(

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 5:47 pm
by snm
Is it not happened until now LC bug? I checked it on versions 5.0.2 to 6.5.2 (MacBook Pro, 10.8.5) - the same problem.

Marek

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 6:09 pm
by bn
Hi Marek,

I am not shure if it is a bug but would consider it as a bug unless someone gives a good explanation for this behavior.

Unfortunately you are very good at discovering bugs in LC :)

Until someone has a better idea I would encapsulate this "bug" or bug like this

Code: Select all

on mouseUp
   put "http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html" & cr & "http://www.nbp.pl/kursy/xml/c027z140210.xml" into tURLList
   repeat with i = 1 to the number of lines of tURLLIst
      put getURL (line i of tURLList) into tRes
      if tRes <> "" then 
         put tRes -- tried 10 times and could not get URL
         exit mouseUp
      end if
   end repeat
end mouseUp
   
function getURL pURL
   repeat 10 -- try 10 times, if success before return "" to stop repeat
      put url pURL into msg
      if the result is "" then
         return ""
      end if
   end repeat
   return "error in getting URL" && pURL
end getURL
Or something similar. This works for me.
That way you don't get stuck if it fails to work

Kind regards
Bernd

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 6:58 pm
by snm
Hi Bernd,

I don't know second url until I parse it from html from first url. The name of xml file i must download is changing minimum once a day. I'm worry only if put second url twice always will be enough. So basing on your help I have idea to check if will work:

Code: Select all

on mouseUp
   local tHtml, tUrl, tXml, tNode
   put url "http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html" into tHtml
   get matchText (tHtml, "(/kursy/xml/[a-zA-Z0-9]+\.xml)" , tUrl)
   put "http://www.nbp.pl" & tUrl into tUrl
   repeat with i=1 to 10
      put url tUrl into tHtml
      if tHtml is not empty then exit repeat
   end repeat
   put revXMLCreateTree (tHtml, false, true, false) into tXml
   put revXMLRootNode (tXml) into tNode
   put revXMLTree (tXml, tNode, return, space, true, -1) into fld "xml"
   revXMLDeleteAllTrees
end mouseUp
Until now it works :)

Once more thanks a lot for your help Bernd,
Marek

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 7:10 pm
by bn
Marek,

you should 1 conditional that tests for tHTML, see code.

Code: Select all

on mouseUp
   local tHtml, tUrl, tXml, tNode
   put url "http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html" into tHtml
   get matchText (tHtml, "(/kursy/xml/[a-zA-Z0-9]+\.xml)" , tUrl)
   put "http://www.nbp.pl" & tUrl into tUrl
   repeat with i=1 to 10
      put url tUrl into tHtml
      if tHtml is not empty then exit repeat
   end repeat
   if tHTML is "" then -- if after 10 tries still no text then exit 
      answer "failure to retrieve URL"
      exit mouseUp
   end if
   put revXMLCreateTree (tHtml, false, true, false) into tXml
   put revXMLRootNode (tXml) into tNode
   put revXMLTree (tXml, tNode, return, space, true, -1) into fld "xml"
   revXMLDeleteAllTrees
end mouseUp
The way you had it the code would have proceeded after 10 tries even without success and the rest of your code would have failed. It is just to make shure you don't run into a problem with this hack.

And I am sure you just added RegEx to please Thierry... :)
Kind regards
Bernd

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 7:47 pm
by snm
Yes Bernd, I didn't finnish this code yet but remember about checking all possible conditions. Actually I was working on another part of this job, but didn't want to keep you waiting for soon response. But thanks for reminder. It's fantastic to have friends who take care of quality and safety of your code.

I'm trying to learn RegEx, so I try to use it as often as possible. But of course it was for Thierry's pleasure - I knew he will want to help also :)

Marek

Re: put URL strange behavior

Posted: Mon Feb 10, 2014 8:47 pm
by Thierry
snm wrote:I'm trying to learn RegEx, so I try to use it as often as possible. But of course it was for Thierry's pleasure
Marek
Thanks guys! You are too nice :)

Thierry