jprichardson / node-google

A Node.js module to search and scrape Google.
MIT License
454 stars 115 forks source link

add search results provided by google #10

Open ianwang opened 10 years ago

ianwang commented 10 years ago

when you google something about date, time, currency, weather, google will provide the answer for you, like

'what time is it?' 'usd eur'

what do you think about adding this kind of results?

jprichardson commented 10 years ago

I think that'd be awesome, I'm just not sure how to do it without really complicating the module. As you're right, Google provides a lot useful answers to questions posed in natural language. But how do you reliably in a non-hacky manner parse results to "what is 2+2", "what time is it in Australia", "define: someword"? I'm not sure that you can. So, it may be best to leave those sorts of queries to the official API. Thoughts?

ianwang commented 10 years ago

I didn't try all of the queries, but I guess there is some certain pattern of it (so far I tested .vk_c), and then basically like what you did:

var linkSel = 'h3.r a'
  , descSel = 'div.s'
  , itemSel = 'li.g'
  , nextSel = 'td.b a span';

I'm happy to send PR, if you don't have much time to test this.

flesler commented 8 years ago

+1 !

Instead of links you should return a result object that has a links attribute plus other attributes.

Other things you could expose on this object:

I think this would simplify the API and make it more extensible without breaking compatibility.

Of course this one change isn't backwards compatible and would require a major version bump. You could make it backwards-compatible if the callback's length is 3 but that might be too hacky.

If you don't want to implement this scraping, I think you should at least change the response to an object like I describe and provide the cheerio object in it to allow custom scraping.

flesler commented 8 years ago

38 proposes a response object, the scrapped result on this issue could be added to it. I actually need it, I can do it on my side once cheerio is exposed but I could add it to this module just as well