-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hccrawler): replace newpage by custom crawl
- Loading branch information
yujiosaka
committed
Jun 10, 2018
1 parent
4f5bac5
commit 96d13f2
Showing
6 changed files
with
96 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const HCCrawler = require('headless-chrome-crawler'); | ||
|
||
(async () => { | ||
const crawler = await HCCrawler.launch({ | ||
customCrawl: async (page, crawl) => { | ||
// You can access the page object before requests | ||
await page.setRequestInterception(true); | ||
page.on('request', request => { | ||
if (request.url().endsWith('/')) { | ||
request.continue(); | ||
} else { | ||
request.abort(); | ||
} | ||
}); | ||
// The result contains options, links, cookies and etc. | ||
const result = await crawl(); | ||
// You can access the page object after requests | ||
result.content = await page.content(); | ||
// You need to extend and return the crawled result | ||
return result; | ||
}, | ||
onSuccess: result => { | ||
console.log(`Got ${result.content} for ${result.options.url}.`); | ||
}, | ||
}); | ||
await crawler.queue('https://example.com/'); | ||
await crawler.onIdle(); | ||
await crawler.close(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters