@microlink/google 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +163 -0
- package/package.json +92 -0
- package/src/index.js +54 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2026 microlink.io <hello@microlink.io> (microlink.io)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# @microlink/google
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
[](https://coveralls.io/github/microlinkhq/microlink-google)
|
|
5
|
+
[](https://www.npmjs.org/package/@microlink/google)
|
|
6
|
+
|
|
7
|
+
> Google search results via [Microlink API](https://microlink.io).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @microlink/google
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Create a client by passing your configuration, then call it with a search query:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
const google = require('@microlink/google')({
|
|
21
|
+
apiKey: 'YOUR_API_KEY',
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const page = await google('Lotus Elise S2')
|
|
25
|
+
|
|
26
|
+
for (const result of page.results) {
|
|
27
|
+
console.log(result.title) // "Lotus Elise - Wikipedia"
|
|
28
|
+
console.log(result.url) // "https://en.wikipedia.org/wiki/Lotus_Elise"
|
|
29
|
+
console.log(result.description) // "The Lotus Elise is a two-seat, ..."
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Each result has a lazy `.html()` method that fetches the full page HTML on demand:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
const html = await page.results[0].html()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The SERP page HTML is also available:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
const serpHtml = await page.html()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Pagination
|
|
46
|
+
|
|
47
|
+
Results are paginated. Call `.next()` to get the next page:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
const firstPage = await google('node.js frameworks')
|
|
51
|
+
const secondPage = await firstPage.next()
|
|
52
|
+
const thirdPage = await secondPage.next()
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The offset is calculated automatically from the number of results in each page.
|
|
56
|
+
|
|
57
|
+
## API
|
|
58
|
+
|
|
59
|
+
### google(query, [options])
|
|
60
|
+
|
|
61
|
+
#### query
|
|
62
|
+
|
|
63
|
+
*Required*<br>
|
|
64
|
+
Type: `string`
|
|
65
|
+
|
|
66
|
+
The search query. Spaces are supported naturally. You can use [Google search operators](https://support.google.com/websearch/answer/2466433) for advanced filtering:
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
// Only PDF files
|
|
70
|
+
const page = await google('annual report filetype:pdf')
|
|
71
|
+
|
|
72
|
+
// Results from a specific site
|
|
73
|
+
const page = await google('security updates site:github.com')
|
|
74
|
+
|
|
75
|
+
// Exclude a site
|
|
76
|
+
const page = await google('node.js tutorials -site:w3schools.com')
|
|
77
|
+
|
|
78
|
+
// Exact phrase
|
|
79
|
+
const page = await google('"machine learning" site:arxiv.org')
|
|
80
|
+
|
|
81
|
+
// Combine operators
|
|
82
|
+
const page = await google('site:reddit.com intitle:best "mechanical keyboard"')
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### options
|
|
86
|
+
|
|
87
|
+
##### limit
|
|
88
|
+
|
|
89
|
+
Type: `number`
|
|
90
|
+
|
|
91
|
+
Maximum number of results to return per page.
|
|
92
|
+
|
|
93
|
+
##### lang
|
|
94
|
+
|
|
95
|
+
Type: `string`
|
|
96
|
+
|
|
97
|
+
Country perspective for ranking results ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code, e.g. `'us'`, `'de'`, `'jp'`).
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
const page = await google('recetas de pasta', { lang: 'es' })
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
##### device
|
|
104
|
+
|
|
105
|
+
Type: `string`<br>
|
|
106
|
+
Values: `'desktop'`, `'mobile'`
|
|
107
|
+
Default: `'desktop'`
|
|
108
|
+
|
|
109
|
+
Device type for SERP layout. Affects how Google renders and ranks results.
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
const page = await google('best restaurants', { device: 'mobile' })
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
##### period
|
|
116
|
+
|
|
117
|
+
Type: `string`<br>
|
|
118
|
+
Values: `'hour'`, `'day'`, `'week'`, `'month'`, `'year'`
|
|
119
|
+
|
|
120
|
+
Time-based filter for results.
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
const page = await google('tech news', { period: 'week' })
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
##### domain
|
|
127
|
+
|
|
128
|
+
Type: `string`<br>
|
|
129
|
+
Default: `'google.com'`
|
|
130
|
+
|
|
131
|
+
Regional Google domain to query (e.g. `'google.de'`, `'google.co.uk'`, `'google.com.tr'`).
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
const page = await google('restaurants', { domain: 'google.co.uk' })
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Page object
|
|
138
|
+
|
|
139
|
+
The return value from a search call is a page object with the following properties:
|
|
140
|
+
|
|
141
|
+
| Property | Type | Description |
|
|
142
|
+
|---|---|---|
|
|
143
|
+
| `results` | `Array<Result>` | Array of search results |
|
|
144
|
+
| `html()` | `() => Promise<string>` | Returns the raw SERP HTML |
|
|
145
|
+
| `next()` | `() => Promise<Page>` | Fetches the next page of results |
|
|
146
|
+
|
|
147
|
+
### Result object
|
|
148
|
+
|
|
149
|
+
Each result in the `results` array has:
|
|
150
|
+
|
|
151
|
+
| Property | Type | Description |
|
|
152
|
+
|---|---|---|
|
|
153
|
+
| `title` | `string` | Page title |
|
|
154
|
+
| `url` | `string` | Direct URL to the page |
|
|
155
|
+
| `description` | `string` | Result snippet text |
|
|
156
|
+
| `html()` | `() => Promise<string>` | Fetches the full HTML of this result's URL via Microlink |
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
**@microlink/google** © [microlink.io](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/microlink-google/blob/master/LICENSE.md) License.<br>
|
|
161
|
+
Authored and maintained by [microlink.io](https://microlink.io) with help from [contributors](https://github.com/microlinkhq/microlink-google/contributors).
|
|
162
|
+
|
|
163
|
+
> [microlink.io](https://microlink.io) · GitHub [microlink.io](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@microlink/google",
|
|
3
|
+
"description": "Google search integration for Microlink",
|
|
4
|
+
"homepage": "https://github.com/microlinkhq/microlink-google",
|
|
5
|
+
"version": "0.0.0",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.js"
|
|
8
|
+
},
|
|
9
|
+
"author": {
|
|
10
|
+
"email": "hello@microlink.io",
|
|
11
|
+
"name": "microlink.io",
|
|
12
|
+
"url": "https://microlink.io"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/microlinkhq/microlink-google.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/microlinkhq/microlink-google/issues"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"google",
|
|
23
|
+
"integration",
|
|
24
|
+
"microlink",
|
|
25
|
+
"search",
|
|
26
|
+
"search",
|
|
27
|
+
"serp"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@microlink/mql": "latest"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@commitlint/cli": "latest",
|
|
34
|
+
"@commitlint/config-conventional": "latest",
|
|
35
|
+
"@ksmithut/prettier-standard": "latest",
|
|
36
|
+
"ava": "latest",
|
|
37
|
+
"c8": "latest",
|
|
38
|
+
"finepack": "latest",
|
|
39
|
+
"git-authors-cli": "latest",
|
|
40
|
+
"github-generate-release": "latest",
|
|
41
|
+
"nano-staged": "latest",
|
|
42
|
+
"simple-git-hooks": "latest",
|
|
43
|
+
"standard": "latest",
|
|
44
|
+
"standard-markdown": "latest",
|
|
45
|
+
"standard-version": "latest"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">= 24"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"src"
|
|
52
|
+
],
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"commitlint": {
|
|
55
|
+
"extends": [
|
|
56
|
+
"@commitlint/config-conventional"
|
|
57
|
+
],
|
|
58
|
+
"rules": {
|
|
59
|
+
"body-max-line-length": [
|
|
60
|
+
0
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"nano-staged": {
|
|
65
|
+
"*.js": [
|
|
66
|
+
"prettier-standard",
|
|
67
|
+
"standard --fix"
|
|
68
|
+
],
|
|
69
|
+
"*.md": [
|
|
70
|
+
"standard-markdown"
|
|
71
|
+
],
|
|
72
|
+
"package.json": [
|
|
73
|
+
"finepack"
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
"simple-git-hooks": {
|
|
77
|
+
"commit-msg": "npx commitlint --edit",
|
|
78
|
+
"pre-commit": "npx nano-staged"
|
|
79
|
+
},
|
|
80
|
+
"scripts": {
|
|
81
|
+
"clean": "rm -rf node_modules",
|
|
82
|
+
"contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
|
|
83
|
+
"coverage": "c8 report --reporter=text-lcov > coverage/lcov.info",
|
|
84
|
+
"lint": "standard-markdown README.md && standard",
|
|
85
|
+
"postrelease": "pnpm release:tags && pnpm release:github && pnpm publish",
|
|
86
|
+
"pretest": "pnpm lint",
|
|
87
|
+
"release": "standard-version -a",
|
|
88
|
+
"release:github": "github-generate-release",
|
|
89
|
+
"release:tags": "git push --follow-tags origin HEAD:master",
|
|
90
|
+
"test": "c8 ava"
|
|
91
|
+
}
|
|
92
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const mql = require('@microlink/mql')
|
|
4
|
+
|
|
5
|
+
const DOMAIN = 'microlink.google'
|
|
6
|
+
|
|
7
|
+
const buildPath = (query, limit, lang) =>
|
|
8
|
+
[encodeURIComponent(query).replace(/%20/g, '+'), limit, lang]
|
|
9
|
+
.filter(v => v !== undefined)
|
|
10
|
+
.join('/')
|
|
11
|
+
|
|
12
|
+
const buildUrl = (query, { limit, lang, device, period, domain } = {}) => {
|
|
13
|
+
const url = new URL(`https://${DOMAIN}/${buildPath(query, limit, lang)}`)
|
|
14
|
+
if (device) url.searchParams.set('device', device)
|
|
15
|
+
if (period) url.searchParams.set('period', period)
|
|
16
|
+
if (domain) url.searchParams.set('domain', domain)
|
|
17
|
+
return url
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const fetchPage = async (url, mqlOpts, offset) => {
|
|
21
|
+
url.searchParams.set('start', String(offset))
|
|
22
|
+
const { data } = await mql(url.toString(), mqlOpts)
|
|
23
|
+
const { results, html } = data
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
html: () => Promise.resolve(html),
|
|
27
|
+
results: results.map(result => ({
|
|
28
|
+
...result,
|
|
29
|
+
html: async () => {
|
|
30
|
+
const { data } = await mql(result.url, {
|
|
31
|
+
...mqlOpts,
|
|
32
|
+
data: { content: { attr: 'html' } }
|
|
33
|
+
})
|
|
34
|
+
return data.content
|
|
35
|
+
}
|
|
36
|
+
})),
|
|
37
|
+
next: () =>
|
|
38
|
+
fetchPage(new URL(url.toString()), mqlOpts, offset + results.length)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = ctxOpts => {
|
|
43
|
+
return async (
|
|
44
|
+
query,
|
|
45
|
+
{ limit, lang, device, period, domain, ...opts } = {}
|
|
46
|
+
) => {
|
|
47
|
+
const url = buildUrl(query, { limit, lang, device, period, domain })
|
|
48
|
+
return fetchPage(url, { ...ctxOpts, ...opts }, 0)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports.buildPath = buildPath
|
|
53
|
+
module.exports.buildUrl = buildUrl
|
|
54
|
+
module.exports.DOMAIN = DOMAIN
|