Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,25 @@ google('node.js best practices', function(err, next, links){
});
```

Specifying a proxy to be used when searching
You can specify the options to be passed to request, see the [request module](https://github.com/request/request) for all available options.

```javascript
var google = require('google');

google.proxy = 'http://user:password@192.168.5.4:80';
google.requestOptions = {
proxy: 'http://user:password@192.168.5.4: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, next, links){
Expand Down
8 changes: 2 additions & 6 deletions lib/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function google(query, callback) {
google.resultsPerPage = 10;
google.tld = 'com';
google.lang = 'en';
google.proxy = null;
google.requestOptions = {};

var igoogle = function(query, start, callback) {
if (google.resultsPerPage > 100) google.resultsPerPage = 100; //Google won't allow greater than 100 anyway
Expand All @@ -30,11 +30,7 @@ var igoogle = function(query, start, callback) {
method: 'GET'
};

//make sure we have a set proxy for the scrape
if (google.proxy != null) {
//set request.proxy to the provided google.proxy
requestOptions.proxy = google.proxy;
}
for (var k in google.requestOptions) requestOptions[k] = google.requestOptions[k];

request(requestOptions, function(err, resp, body) {
if ((err == null) && resp.statusCode === 200) {
Expand Down