Skip to content

Commit fae39f7

Browse files
committed
Add limit prop to config.
1 parent 30fc290 commit fae39f7

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ Whether or not Puppeteer should run in [headless mode](https://www.browserstack.
147147

148148
Defaults to `true`
149149

150+
#### limit
151+
The total number of articles that you would like to be returned. Please note that with higher numbers, the actual returned number may be lower. Typically the max is `99`, but it varies depending on many variables in Puppeteer (such as rate limiting, network conditions etc.).
152+
153+
Defaults to `99`
154+
150155
## TypeScript 💙
151156
Google News Scraper includes full [TypeScript](https://typescriptlang.org/) definitions.
152157

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const googleNewsScraper = async (userConfig: GNSUserConfig) => {
2424
puppeteerHeadlessMode: true,
2525
logLevel: 'error',
2626
timeframe: '7d',
27-
queryVars: {},
27+
queryVars: {},
28+
limit: 99
2829
},
2930
...userConfig,
3031
} as GNSConfig;
@@ -133,7 +134,8 @@ const googleNewsScraper = async (userConfig: GNSUserConfig) => {
133134
await page.close();
134135
await browser.close()
135136

136-
return results.filter(result => result.title)
137+
const filtered = results.filter(result => result.title);
138+
return config.limit < results.length ? filtered.slice(0, config.limit) : filtered;
137139

138140
}
139141

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type GNSUserConfig = SearchParams & {
1818
logLevel?: LogLevel;
1919
queryVars?: QueryVars;
2020
filterWords?: string[];
21+
limit?: number;
2122
};
2223

2324
export type GNSConfig = SearchParams & {
@@ -29,6 +30,7 @@ export type GNSConfig = SearchParams & {
2930
logLevel: LogLevel;
3031
queryVars: QueryVars;
3132
filterWords?: string[];
33+
limit: number;
3234
};
3335

3436
export type Article = {

0 commit comments

Comments
 (0)