Results 1 to 7 of 7
-
Help with parsing website with regex please
I want to add google maps direction to my program (its free to add it to your website so it shouldnt be a problem)
But the problem is that the code they give you (although working on the demo example) doesn't work when you put it in your website. It has some error in the JS file which you are linking but can't access. So anyway I decided to do it manually.
To get directions with google maps, you need to use this URL:
It loads up a google map search page with the directions to the left. Its too much for me, I only need the direction text. So I had a look at the code and found that the page contains the information i need like this:Java Code:http://maps.google.com/maps? saddr=stanyan+st%2C+san+francisco &daddr=twin+peaks+blvd%2C+san+francisco where saddr= is followed by the Start ADDRess and daddr= is followed by the Destination ADDRess
Java Code:Directions title * needs to be found like this: "<div id=\"dir_title\">*</div>" Directions instructions need to be found between the first instance of: "<td class=\"dir-cb-cbicon\">" and the last instance of: "<td class=\"dir-cb-cbicon\">"
So first I need to download the URL.
FIRST QUESTIONJava Code://compile URL String mapURLstr = "http://maps.google.com/maps?saddr=" + DIR_START + "&daddr=" + DIR_FINISH; URL mapURL = new URL(mapURLstr);
obviously the URL needs to be in the form where spaces are replaced with '+' and commas replaced with '%2C', so is there are java package built in to convert a string to a URL-friendly URL, or will this not be a problem by invoking new URL(urlString); ?
SECOND QUESTIONJava Code://download page to parse BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(mapURL.openStream())); //rebuild page String s; StringBuilder builder = new StringBuilder(); while ((s = bufferedReader.readLine()) != null) { builder.append(s); } String mapHTML = builder.toString();
How do I use the regex patterns to extract the required information as stated at the beginning of this post or delete the unwanted information from the String 'mapHTML'?
Thanks for your helpLast edited by ozzyman; 04-08-2011 at 06:43 PM.
- 04-08-2011, 07:00 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Mhm i think thats not correct! Its even forbidden to use the official direction API without a google map!
The Google Directions API - Google Maps API Web Services - Google Code
"[...]Note: the Directions API may only be used in conjunction with displaying results on a Google map; using Directions data without displaying a map for which directions data was requested is prohibited. Additionally, calculation of directions generates copyrights and warnings which must be displayed to the user in some fashion.[...]"
-
Ohh I see, well thanks for that. So I guess it isn't allowed unless I show the map too. But I don't think they'd find out :S. All i'm doing is downloading their page to my hard drive, its like opening a web browser. Once the page is on my hard drive, I'm just doing myself the pleasure of showing myself only the parts that I need.
Oh and I just remembered, I AM going to show the map with it, only I'm going to use the STATIC map address because its lighter and loads faster and doesnt contain any javascript. So it will be fine.
Check this link out to see what i'm talking about:
Driving Directions Gadget
its a compact tool for your website which doesn't contain the whole page as such, it just shows the directions + an interactive map.
What i'm planning on doing is getting the same thing, but directions + static map, manually.
- 04-08-2011, 07:17 PM #4
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Are you talking about a webapplication or a desktop application?
Google Maps/Google Earth APIs Terms of Service - Google Maps API Family - Google Code
"[...](h) No Use of Static Maps API(s) outside a Web-Based Application (Except with a Link to Google Maps). You must not use the Static Maps API(s) outside of a web-based application unless:
(i) your platform does not have a web browser; or
(ii) if your platform does have a web browser, you provide a link that shows the location concerned either (x) in the Google Maps native application (if your platform has one); or (y) on the Google Maps website.[...]"
;)
I recommend you to use the API of CloudMade.com ;)
-
really, all i need is a simple map with simple directions. i looked at CloudMade.com's Mapzen, its too much for me.
its for a desktop application. the number of requests would never exceed 2,500 requests per day so it would never be enough for google to look into how i'm using their data. furthermore, the desktop application i plan on using on different computers (with different IPs) so each copy would have its own limit of 2,500 because it is simple downloading the website AS IS so there is no noteable difference in how the page is being viewed Except the web browser. (if a java application downloads a webpage, what does the browser name come up as if you had a browser sniffer?)
-
does anyone have any guidance regarding the extraction of data with regex from the string?
-
Similar Threads
-
need help with regex
By o2a1 in forum New To JavaReplies: 3Last Post: 02-13-2011, 12:53 AM -
Regex help?
By l3ane in forum New To JavaReplies: 6Last Post: 01-18-2011, 06:04 AM -
Using Regex
By ron87 in forum New To JavaReplies: 4Last Post: 09-12-2010, 06:26 AM -
Please Help - Regex
By BeeGee in forum Advanced JavaReplies: 0Last Post: 04-28-2010, 05:28 PM -
How to download website (Get all link in website)
By finalmem in forum Advanced JavaReplies: 0Last Post: 11-12-2008, 08:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks