HTTPRequest help

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
obfusc88
Pro Scripter
Posts: 89
Joined: Wed Mar 14, 2007 6:22 pm

HTTPRequest help

Post by obfusc88 » Tue Sep 02, 2008 12:44 am

I have been trying to get some map information with no success, just want estimated travel distance and time.

I have been trying googlemaps, yahoomaps and mapquest.
The closest I have come to success is with MapQuest.

It is only a single command but I cannot get what I need.
HTTPRequest>http>//mapquest.com/maps?1z=80202&2z=33602,,GET,Result

This connects, but does not provide the info I am looking for, I need the Total Estimated Time and the Total Estimated Distance, but both pieces of information are missing on the Result page.

If I go to the browser and paste the URL in directly, it show the correct result.
If I go to the input page and input the two zipcodes, 80202 and 33602, it shows the correct result.

I have tried using POST vs. GET, that does not connect.
I have tried the following lines also:
HTTPRequest>http://maps.google.com,,GET,saddr=80202&daddr=33602,Result. Again, I get a Result page, but those elements are not filled in. The correct cities show up, but no time/miles
I lost the lines I tried with Yahoo Maps, but that also failed.
Am I making a syntax error? I am not going through a proxy. Does this need some type of delay or refresh? The Result is immediate.
I have not tried using Execute with the the URL as part of the command line, because i want to get the information back without opening up the browser.

This seems like some type of web server control to prevent automation of map retrieves? Any suggestion on how to get the time and miles? I am not particular about any specific source that is relatively accurate for US destinations.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue Sep 02, 2008 2:47 am

If you look at the source of those pages in your browser (View, Source) you will see they are not simple html pages and the source you see contains variables rather than the values you are seeking.

One solution would be to use Yahoo's simpler "dial up" map page, eg

http://maps.yahoo.com/dd_result.php?q1= ... 3=&q4=&q5=

which does have the values in the source.

Using the API available from yahoo or google which allows programs to be run against their databases would be another, more complex, solution.

obfusc88
Pro Scripter
Posts: 89
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Tue Sep 02, 2008 12:42 pm

Thanks for the yahoo link, but that is the same as the one I used. The distance and time are not available in the Return variable or in a returned file.

If I use Firefox ViewSource, those values are not present in the Source Code. If I use and AddOn, ViewSourceChart, then the values are there. So all View Source tools are not the same. The information I need is in an object whose id = "ymap_user_directions_distance". Is there a way to GET that object info vs. the whole page? (Again, the whole page Result does not include that info, I can only see it with another "visible" utility tool). If I use MSIE, the ViewSource also does not include the time/distance values.

Again, even if it is visible in the source code it must be in the Result that comes back with HTTPRequest so that the browser is not opened. If I worked with the browser opened, I could probably use FindImage to locate the numbers.

I suspect that working with an API is beyond my current skills.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue Sep 02, 2008 1:09 pm

Sorry that didn't work out. I now see that URL accessed directly does get you to the same page, so there must be something else that is switching the display to the "dial up" version which has the info visible in the source:

Distance: 1862.5 milesTime: 27 hours 44 mins (approx.)

:(

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue Sep 02, 2008 3:54 pm

If you use google maps and direct the output to a kml file then you will have the info you need in the result. e.g.

Code: Select all

HTTPRequest>http://maps.google.com/maps?q=from+80202+to+33602&output=kml,,GET,,output
You do need to be sure that using their site this way does not violate google maps terms and conditions which can be found here.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Sep 02, 2008 10:00 pm

This site (zip-codes.com) works to get the Distance. The value is in the Result file. Time is not available from here.
You can then parse out the mileage from %Result%

Code: Select all

HTTPRequest>http://www.zip-codes.com/distance_calculator.asp?zip1=80202&zip2=33602&Submit=Search,,POST,zip1=80202%&zip2=33602,Result

// Miles are in this format "">9,999.99</b> miles or" - locate it.
Position></b> miles or,%Result%,1,ThisLine
//Check for error
If>%ThisLine%=0,Error

// Retrieve whole hundreds of miles, no decimal, no thousands or comma
Let>Start=%ThisLine%-6
MidStr>%DestinationResult%,%Start%,3,Mileage
// Strip off leading characters (">) if larger than 999
StringReplace>%Mileage%,",,Mileage
StringReplace>%Mileage%,>,,Mileage
Message>Distance is %Mileage%
GoTo>End

Label>Error
MessageModal>Bad Zip Code

Label>End



Last edited by Bob Hansen on Tue Sep 02, 2008 11:12 pm, edited 1 time in total.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue Sep 02, 2008 10:23 pm

I played with one of those sites too, http://www.melissadata.com/lookups/zipdistance.asp, but I think they are giving straight line distance rather than road travel distance. May be OK for obfusc88's purpose though (especially for longer distances) and it would be easy to divide by a speed of your choice to get a time estimate.

obfusc88
Pro Scripter
Posts: 89
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Wed Sep 03, 2008 3:58 am

Thank you all for your suggestions and links. I did end up selecting the google link from Me_again. It includes the miles and the estimated time.

It took me a while to understand how Bob Hansen was parsing the miles, but now I understand that and can use that approach with the Result file that comes back from google.

obfusc88
Pro Scripter
Posts: 89
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Wed Sep 03, 2008 5:58 pm

Now I need help with parsing.

This works:

Code: Select all

//Get miles
Let>ThisLine=Distance: 1,382##160;mi (about 22 hours 31 mins)
Position>&#,%ThisLine%,11,MilesEnd
MidStr>%ThisLine%,11,%MilesEnd%,Miles
StringReplace>%Miles%,&,,Miles
MessageModal>Distance is %Miles% miles.
%ThisLine% is the line I was able to parse out from %Result%. I am trying to get the 1,382 portion of the miles. I have had to use the forum display to show "##" vs. the real "&#" that is %ThisLine%. I have disabled HTML but that did not work. The "&#" is being used as a space character.

But I was not able to get Position to give me the correct value for %MilesEnd%. No matter, what I did, I kept getting value of 6 vs. 5 for the position of "&#" starting from position 11.

Finally as a work around, I accepted the value of 6 and used StringReplace to drop the "&" character from the "1,382&".

So, I have parsed out the miles, but Position does not seem to be working correctly looking for the "&" character. What did I do wrong?

(Should I have posted this in an earlier topic about trouble with Position? Does this have to deal with unicode or something like that?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Sep 03, 2008 7:56 pm

6 is the correct result.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Sep 04, 2008 12:50 am

Marcus is correct.....
Look at it like this:
Start at 1,382&#, want to get position that ## starts

value 1 = position 1
value , = position 2
value 3 = position 3
value 8 = position 4
value 2 = position 5
value & = position 6
value # = position 7

&# starts at position 6, maybe you were forgetting about the comma?

Change your code to add a line like this, then no need to replace a character:
//Get miles
Let>ThisLine=Distance: 1,382&#mi (about 22 hours 31 mins)
Position>&#,%ThisLine%,11,MilesEnd
Let>MilesEnd=%MilesEnd%-1
MidStr>%ThisLine%,11,%MilesEnd%,Miles
MessageModal>Distance is %Miles% miles.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts