• Stars
    star
    454
  • Rank 96,373 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Node.js module to search and scrape Google.

Node.js - google

build status

This module allows you to search google by scraping the results. It does NOT use the Google Search API. PLEASE DO NOT ABUSE THIS. The intent of using this is convenience vs the cruft that exists in the Google Search API.

This is not sponsored, supported, or affiliated with Google Inc.

Please do not post an issue, email me, tweet me, or in anyway contact me about getting around Google blocking your automated search requests. These sorts of requests are outside the scope of this module. Google has every right to block consumers of their service for any reason. See: #27, #20.

js-standard-style

Installation

npm install --save google

API Example

This prints out the first 100 search results of the query node.js best practices.

var google = require('google')

google.resultsPerPage = 25
var nextCounter = 0

google('node.js best practices', function (err, res){
  if (err) console.error(err)

  for (var i = 0; i < res.links.length; ++i) {
    var link = res.links[i];
    console.log(link.title + ' - ' + link.href)
    console.log(link.description + "\n")
  }

  if (nextCounter < 4) {
    nextCounter += 1
    if (res.next) res.next()
  }
})

Search Within a Time Span

You can specify results in a specific timeframe. Working values listed below:

var google = require('google')

// assign one of the values below. Nothing is set by default.
google.timeSpan = 'h' // information indexed in the past hour
google.timeSpan = 'd' // information indexed in the past day
google.timeSpan = 'w' // information indexed in the past week
google.timeSpan = 'm' // information indexed in the past month
google.timeSpan = 'y' // information indexed in the past year

Search Within Different Languages

You can also specify the TLD of the Google search page and the language. If you change the language you must translate the next page results text to detect the corresponding link.

var google = require('google')

google.lang = 'de'
google.tld = 'de'
google.nextText = 'Weiter'

google('node.js best practices', function (err, res){
  …
})

Set Request Options

You can specify the options to be passed to request, see the request module for all available options.

var google = require('google')

google.requestOptions = {
  proxy: 'http://user:[email protected]:80',
  timeout: 30000,
  localAddress: '127.0.0.1',
  jar: true,
  headers: {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'en;q=0.5',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    'DNT': 1
  }
}

google('node.js best practices', function (err, res){
  …
})

Setting the protocol

A 'http' or 'https' protocol can be specified after the google object has been created for queries. For example specifying 'http' will search google using the a http://www.google.com query where 'https' will use a https://www.google.com query. If no protocol is specified or any other protocol other then 'http' or 'https' is explicitly passed then this will be set to 'https' by default.

var google = require('google')

google.protocol = 'http'  // searches google using http://www.google.com
google.protocol = 'https' // searches google using https://www.google.com

google('node.js best practices', function (err, res){
  …
})

The response object

The provided callback will receive a response object as second argument, it has these properties:

  • url: The URL requested from Google for this search and page
  • query: The search provided on this call
  • start: The index of the first link across the links of all pages
  • links: An array with all the link objects
  • body: The HTML of the loaded page
  • next: A method that invokes the originally specified callback with next page results
  • $: A cheerio instance of the loaded page

Updating from 1.x

The only backwards-incompatible change from 1.x is that the callback received 3 arguments:

google('...', function (err, next, links) {
  links.forEach(function(link) { ... })
  if (next) next()
})

And it now receives a single res object. The above code should be rewritten to:

google('...', function (err, res) {
  res.links.forEach(function(link) { ... })
  if (res.next) res.next()
})

License

Licensed under MIT. See LICENSE for more details.

Copyright (c) 2012-2016 JP Richardson

More Repositories

1

node-fs-extra

Node.js: extra methods for the fs object like copy(), remove(), mkdirs()
JavaScript
9,368
star
2

string.js

Extra JavaScript string methods.
JavaScript
1,803
star
3

node-jsonfile

Easily read/write JSON files.
JavaScript
1,203
star
4

sublime-js-snippets

Snippets for JavaScript / JS Programming in Sublime Text 2 & 3
407
star
5

electron-mocha

Run Mocha tests in Electron
JavaScript
345
star
6

node-klaw

A Node.js file system walker with a Readable stream interface. Extracted from fs-extra.
JavaScript
316
star
7

electron-window

Convenience methods for Electron windows.
JavaScript
290
star
8

node-suppose

Like UNIX Expect, but for Node.js.
JavaScript
252
star
9

node-death

Gracefully cleanup when termination signals are sent to your process.
JavaScript
182
star
10

electron-ipc-stream

Duplex stream that runs over Electron's IPC
JavaScript
152
star
11

asciiflow

ASCII diagrams and drawing on the web (GWT)
Java
135
star
12

tin

Easily manage package.json, component.json, and bower.json files.
JavaScript
92
star
13

is-electron-renderer

Check if code is running in Electron renderer process
JavaScript
78
star
14

node-github-download

Easily download Github repos without dependencies such as Git, Tar, Unzip, etc.
JavaScript
76
star
15

secure-random

A simple JavaScript component to normalize the creation of cryptographically strong random values.
JavaScript
62
star
16

iceden

Maybe something like Firebase?
JavaScript
60
star
17

GeneratePushCerts

Automation of Generating Push Certificates for iOS Devices
Ruby
57
star
18

node-batchflow

Batch process collections in parallel or sequentially.
JavaScript
51
star
19

node-kexec

Node.js exec function to replace running process; like Ruby's exec.
C++
50
star
20

tape-promise

Promise and async/await support for Tape
JavaScript
46
star
21

talks-ncc3-demo

Demo from Nebraska Code Camp #3
JavaScript
40
star
22

node-nextflow

A simple control-flow library for Node.js targetted towards CoffeeScript developers.
CoffeeScript
38
star
23

node-scrap

A simple screen scraper module that uses jQuery style semantics.
JavaScript
33
star
24

react-qr

A React.js QR Code component.
JavaScript
32
star
25

ansible-redis

Ansible playbook to install redis.
Shell
29
star
26

node-canada

Cities and provinces from Canada for JavaScript
JavaScript
29
star
27

cross-zip-cli

Zip/Unzip directories cross platform from the CLI. Great for npm scripts.
JavaScript
26
star
28

node-path-extra

Node.js: extra methods for the path object.
JavaScript
23
star
29

readline-go

golang: Easily read lines from a stream such as `stdin` for a file. Supports either `\n`, `\r\n`, or mixed.
Go
22
star
30

least-squares

JavaScript component for linear least squares regression analysis.
JavaScript
19
star
31

CommonLib

A .NET Library With Utility Classes and Methods
C#
19
star
32

node-linkscrape

A Node.js module to scrape and normalize links from an HTML string.
JavaScript
15
star
33

FridayThe13th

Fast JSON Parser for Silverlight or .NET
C#
14
star
34

ip-location

Get an IP or hostname location geo coordinates.
JavaScript
14
star
35

jsock

JavaScript component for easy JSON handling over sockets or streams. Works in Node.js or the browser.
JavaScript
13
star
36

rr

A simple JavaScript component to iterate an array round robin.
JavaScript
12
star
37

node-packpath

Easily find the path(s) of package.json.
JavaScript
12
star
38

node-markdown-extra

Extra markdown methods.
JavaScript
12
star
39

buffer-json

JSON reviver/replacer methods for JavaScript Buffer type.
JavaScript
12
star
40

npm-latest

Quickly find the latest version of a package in npm.
JavaScript
12
star
41

keychain_manager

Ruby Gem for OS X Keychain Access
Ruby
11
star
42

npm-research

Nice little utility to help you research NPM packages.
JavaScript
10
star
43

bitcoin-faucet

A Node.js app to easily create a programmable Bitcoin Testnet faucet. This allows you to easily test your Bitcoin applications.
JavaScript
10
star
44

logmeup

LogMeUp Server - View any log files real-time in your web browser.
JavaScript
10
star
45

fix-dropbox-node_modules-symlinks

Fix Dropbox `node_modules/.bin/` symlinks.
JavaScript
10
star
46

mars

Forget live coding, easy code demos.
JavaScript
9
star
47

angular-bluebird

An AngularJS service for Bluebird promise library.
JavaScript
8
star
48

atom-rename-tabs

Rename tabs titles with previous directory. Consistent with Sublime Text Editor behavior.
JavaScript
8
star
49

node-cfs

Node.js conditional file streams
JavaScript
7
star
50

d3-measure-text

A JavaScript component to measure the the width and height of SVG text.
JavaScript
7
star
51

d3-dragrect

A JavaScript D3 drag selection rectangle component.
JavaScript
6
star
52

secret-box

Encrypt and decrypt secrets. Built on AES-256-GCM and Scrypt for now.
JavaScript
6
star
53

MemMapCache

A .NET caching solution that uses memory mapping.
C#
5
star
54

ospath

A JavaScript component that provides operating specific path values.
JavaScript
5
star
55

jsontocsv

Convert lines of JSON data to CSV
JavaScript
5
star
56

d3-tooltip

This is a JavaScript d3 tooltip component.
JavaScript
5
star
57

mongo_install

Ruby script to install download, install, and setup MongoDB as a service on a Ubuntu or Debian box.
Ruby
5
star
58

potter-wordpress

Command line tool to export WordPress to static Markdown.
JavaScript
5
star
59

node-batchtransform

Batch transform/convert a collection of files e.g. convert a collection of markdown template files to html files.
JavaScript
5
star
60

is-async-fn

Check if something is an ES7 async function.
JavaScript
4
star
61

cb-insight

Common Blockchain wrapper for Bitpay Insight API
JavaScript
4
star
62

node-dh

Distributed hash. Simple Node.js wrapper for Redis hash.
JavaScript
4
star
63

spend

A JavaScript component to create simple Bitcoin / Testnet transactions for integration testing with the actual network.
JavaScript
4
star
64

ripdb

100% JavaScript embeddable JSON time series database.
JavaScript
4
star
65

node-worddump

Dump or Export your WordPress blog content.
JavaScript
3
star
66

procbits.com

Home of my current coding blog.
HTML
3
star
67

react-password

A React.js component for password inputs.
JavaScript
3
star
68

ansible-rethinkdb

Ansible playbook to setup a RethinkDB.
3
star
69

node-readline-prompter

Easily prompt the user with a series of questions.
JavaScript
3
star
70

issue-links

Help to keep tidy `CHANGELOG.md`/`HISTORY.md` files by keeping your GitHub Issue links up to date.
JavaScript
3
star
71

atom-javascript-standard-snippets

JavaScript Standard Style Snippets for Atom
CoffeeScript
3
star
72

pottercms

https://github.com/skywrite/sky
JavaScript
3
star
73

d3-chart

A simple JavaScript D3.js chart.
3
star
74

create-output-stream

Node.js: exactly like `fs.createWriteStream`, but if the directory does not exist, it's created.
JavaScript
3
star
75

node-wp2md

Convert your WordPress blog to Markdown.
JavaScript
3
star
76

node-parentpath

Find a path in a parent directory.
JavaScript
3
star
77

buzz

Keep an app running indefinitely, kill it occasionally if you want.
JavaScript
3
star
78

cooking-recipes

I'm starting to write down recipes that I've tried.
3
star
79

node-tweezers

Extract mustache tokens from a file or string.
JavaScript
2
star
80

node-logmeup

Node.js plugin to interface to LogMeUp
CoffeeScript
2
star
81

node-testutil

Node.js testing utilities
JavaScript
2
star
82

node-autoresolve

A simple Node.js module to auto resolve package paths.
JavaScript
2
star
83

ip-location-cli

Command line utility to fetch IP geo location or your own location.
JavaScript
2
star
84

electron-menu

Convenience module to build Electron menu templates.
JavaScript
2
star
85

node-batchfile

JavaScript
2
star
86

node-vcsurl

Convert VCS repository URLs like Github or Bitbucket to their http equivalents.
JavaScript
2
star
87

node-markdown-page

Methods for parsing a markdown page for a blog post or documentation.
JavaScript
2
star
88

node-dq

Simple Node.js priority queue built on Redis.
JavaScript
2
star
89

ymd

JavaScript component to return the year, month, and day string.
JavaScript
2
star
90

terst

A JavaScript testing component with a terse syntax. Supported in both Node.js and the browser.
JavaScript
2
star
91

browser-storage

Normalizes local-storage behavior between node and browser
JavaScript
2
star
92

is-os-cli

CLI utility to check if operating system. Useful for npm scripts.
JavaScript
2
star
93

prevent-backspace

Prevents the backspace from navigating back in the browser.
JavaScript
2
star
94

goatee-go

Non-verbose testing in Go
Go
1
star
95

node-markdown-walker

Simple directory walker that specifically looks for markdown files.
JavaScript
1
star
96

node-cl

Easily create command line programs and interfaces in Node.js.
JavaScript
1
star
97

node-proxyinfo

Get information about HTTP proxy servers
CoffeeScript
1
star
98

trinity

JavaScript
1
star
99

node-qflow

A very simple data queue processing library.
JavaScript
1
star
100

ansible-phantomjs

Ansible playbook to install PhantomJS on Ubuntu server(s).
1
star