DefinitelyTyped/types/website-scraper/website-scraper-tests.ts
garyking 05926a90ea website-scraper: Make Source.attr optional. Add more options. (#40137)
* Make `attr` optional.

As per the defaults:

050cdd0112/lib/config/defaults.js

* Capitalize interface `Scrape`

* Use `any[]` format for array

* add missing semicolon

* add line breaks between interfaces

* convert to single quotes

* remove `attr` for a test

* add more options
2019-11-06 08:51:35 -08:00

34 lines
1014 B
TypeScript

import scraper = require('website-scraper');
scraper({
urls: [
'http://nodejs.org/',
{ url: 'http://nodejs.org/about', filename: 'about.html' },
{ url: 'http://blog.nodejs.org/', filename: 'blog.html' },
],
directory: '/path/to/save',
subdirectories: [
{ directory: 'img', extensions: ['.jpg', '.png', '.svg'] },
{ directory: 'js', extensions: ['.js'] },
{ directory: 'css', extensions: ['.css'] },
],
sources: [
{ selector: 'img' },
{ selector: 'link[rel="stylesheet"]', attr: 'href' },
{ selector: 'script', attr: 'src' },
],
request: {
headers: {
'User-Agent':
'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D)\
AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19',
},
},
})
.then(function(result) {
console.log(result);
})
.catch(function(err) {
console.log(err);
});