1

This one is puzzling me...

For my Android application I want to be able to return the current time in any location the user requests (right down to city level). The request itself comes from a voice command, so I cannot use alternative methods.

The most obvious way (so I thought) was to query Google, but I need your brains to help me solve how to extract the data I want please!

In Google, query:

"What's the time in China"

You should see a 'widget' at the top displaying the answer nicely. View the page source and search on 'China' and it's there - I thought great, this is going to be easy!

But...

"What's the time in London"

Although the display in Google appears the same, there is no result for 'London' when searching the source HTML...?

Using Google Chrome, I inspect the element of the 'widget' and can then view the contents I wish to extract in all cases.

So, my questions is firstly, am I missing something obvious (Google don't want us to be able to do this for example)? Or is there a way to 'force' the result to be in the HTML by structuring the query perhaps?

Secondly, is there a way to access the specific 'element container' and return the results to my Android Application?

I thank you in advance...

brandall
  • 6,094
  • 4
  • 49
  • 103
  • 1
    I'm sorry andjav, I am unable to reproduce your problem. If I put in: https://www.google.com/search?q=What's%20the%20time%20in%20China and I view the source, I can clearly see the answer about 3/4 of the way down, just like if I put in: https://www.google.com/search?q=What's%20the%20time%20in%20London Are you certain that there was no result for London? Maybe I'm missing something? :-P – Jared Apr 24 '12 at 15:53
  • Well it's very odd.. Now when I do the search for London, the time is in the HTML!? So I randomly tried Hong Kong but although shown at the top of Google same as the others, searching the source for the time or 'HKT' produced nothing... Clueless as to why it's only there sometimes? Well, for me anyway! – brandall Apr 29 '12 at 14:09

1 Answers1

1

You should really use an API instead of parsing html. I guess there are many many API which will give you the time in a given city. http://www.worldweatheronline.com/time-zone-api.aspx for example (havnt tried it myself)

If you still want to extract data from the google result (which is html), check for html parsers like in this post : Parse HTML in Android

Community
  • 1
  • 1
Estragon
  • 1,462
  • 11
  • 12
  • Good find! Thank you, I thought I'd searched the depths of Google for something like that. I'd only found premium APIs before. I signed up and it works like a charm. Up-voted your answer, but I haven't accepted it, as I'm still intrigued to know about the Google search as I may require it for similar results - hoping someone will answer that. Thanks again. – brandall Apr 20 '12 at 10:00