KenNichols Posted April 17, 2009 Share Posted April 17, 2009 I am new to working with web pages with AutoIt and still kinda new to working with AutoIt in general. What I am trying to do is extract how many miles it is from point A to point B. $start = InputBox("Starting Address","Enter your starting address:") $end = InputBox("Ending Address","Enter your ending address:") $url = "http://maps.google.com/maps?f=d&hl=en&saddr="&StringReplace($start," ","+")&"&daddr="&StringReplace($end," ","+") RunWait("rundll32.exe url.dll,FileProtocolHandler " & $url, @WorkingDir) After the web page is displayed I need to extract how many miles it is between the start and end address. It's right there on the page but I do not know how to pull the information out. [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner! Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 17, 2009 Share Posted April 17, 2009 I am new to working with web pages with AutoIt and still kinda new to working with AutoIt in general. What I am trying to do is extract how many miles it is from point A to point B.$start = InputBox("Starting Address","Enter your starting address:")$end = InputBox("Ending Address","Enter your ending address:")$url = "http://maps.google.com/maps?f=d&hl=en&saddr="&StringReplace($start," ","+")&"&daddr="&StringReplace($end," ","+")RunWait("rundll32.exe url.dll,FileProtocolHandler " & $url, @WorkingDir)After the web page is displayed I need to extract how many miles it is between the start and end address.It's right there on the page but I do not know how to pull the information out.That will open the user's default browser, which may NOT be IE.Examine the page with a DOM inspector like DebugBar to see where the text you want is, then get it using the _IE* functions of the IE.au3 UDF. If it's not buried inside frames, you might get it with just _IEBodyReadText() and a StringRegExp(). Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jchd Posted April 18, 2009 Share Posted April 18, 2009 (edited) Examine the page with a DOM inspector like DebugBar to see where the text you want is, then get it using the _IE* functions of the IE.au3 UDF. If it's not buried inside frames, you might get it with just _IEBodyReadText() and a StringRegExp(). I believe there's a simpler way: Just after posting, I realized there was a visual "side effect" here! Look, between the 2 regex captures, there was an "ampersand#160;" code (an html hard whitespace) which was immediately transformed into a real hard whitespace by posting the code in ... an html page! Now there's the .* (limited by non greediness) instead. CODE#include <inet.au3> $start = InputBox("Starting Address","Enter your starting address:") $end = InputBox("Ending Address","Enter your ending address:") $url = "http://maps.google.com/maps?f=d&hl=en&output=html&saddr="&StringReplace($start," ","+")&"&daddr="&StringReplace($end," ","+") ;; note the new parameter here --------------^^^^^^^^^^^^ $html = _InetGetsource($url) ;; gets the source without having to bother with any window If @error Then MsgBox(0, "", "An error occured while capturing Web page source!") Exit EndIf ;; Capture distance and unit $data = StringRegExp($html, "(?U)dditd><div><b>([0-9.]*).*([a-z]*)", 1) If @error <> 0 Then MsgBox(0, "", "An error occured while extracting data" & @LF _ & "Page format did change. Check new source html code.") Exit EndIf ConsoleWrite($data[0]) ;; handle $data[*] gracefully here MsgBox(0, "Result", "Distance is " & $data[0] & " " & $data[1]) You'll have to barricade against all sorts of errors (e.g. incomplete or ambiguous user input), but it can be done. Edited April 18, 2009 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
DaleHohm Posted April 18, 2009 Share Posted April 18, 2009 #include <IE.au3> $start = InputBox("Starting Address","Enter your starting address:") $end = InputBox("Ending Address","Enter your ending address:") $sUrl = "http://maps.google.com/maps?f=d&hl=en&saddr="&StringReplace($start&"&daddr="&$end," ","+") $oIE = _IECreate($sUrl) $oDiv = _IEGetObjById($oIE, "dditd") ConsoleWrite(_IEPropertyGet($oDiv, "innertext") & @CRLF) Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
KenNichols Posted April 22, 2009 Author Share Posted April 22, 2009 Let me start out by thanking all 3 of you! I did download DebugBar and I understand this a whole lot better! I am having trouble understanding StringRegExp now. If $Result = ###.# then it works fine but if it = #,### then it comes up #,# and not #,###. I hope this makes sense to someone! $data = StringRegExp($Result, "([0-9]*.[0-9])",1) [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner! Link to comment Share on other sites More sharing options...
Valuater Posted April 22, 2009 Share Posted April 22, 2009 I am having trouble understanding StringRegExp now.That is for another thread, please start a new thread for StringRegExp8) Link to comment Share on other sites More sharing options...
EdWilson Posted May 2, 2013 Share Posted May 2, 2013 #include <IE.au3> $start = InputBox("Starting Address","Enter your starting address:") $end = InputBox("Ending Address","Enter your ending address:") $sUrl = "http://maps.google.com/maps?f=d&hl=en&saddr="&StringReplace($start&"&daddr="&$end," ","+") $oIE = _IECreate($sUrl) $oDiv = _IEGetObjById($oIE, "dditd") ConsoleWrite(_IEPropertyGet($oDiv, "innertext") & @CRLF) Wanting to be able to grab (driving) mileage values from Google as well, and grateful for this and a similar thread. Given that the above code no longer seems to work, I'm wondering if Google perhaps changed their data structure...are we looking for something other than "dditd"? Was this prior to Google incorporating various suggested routes? Any clues? Thanks, Ed Link to comment Share on other sites More sharing options...
EdWilson Posted May 3, 2013 Share Posted May 3, 2013 Ahhh, this was simple. It is the html id="altroute_0" that we are looking for, so simply changing dditd to altroute_0 in the above code does the trick. Can get altroute_1 or altroute_2 as well if those are presented. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now