Fix commonjs import method (#16297)

This commit is contained in:
Balazs Erdos
2017-05-03 12:42:40 -07:00
committed by Mohamed Hegazy
parent e93d87a899
commit 2e9178c4b5
2 changed files with 23 additions and 17 deletions
+6 -2
View File
@@ -43,8 +43,12 @@ declare namespace websiteScraper {
interface Callback {
(error: any | null, result: Resource[] | null): void;
}
function scrape(options: Options, callback: Callback): void;
function scrape(options: Options): Promise<Resource[]>;
interface scrape {
(options: Options, callback: Callback): void;
(options: Options): Promise<Resource[]>;
}
}
declare var websiteScraper: websiteScraper.scrape;
export = websiteScraper;
+17 -15
View File
@@ -1,29 +1,31 @@
import * as scraper from 'website-scraper';
import * as scraper from "website-scraper";
scraper.scrape({
scraper({
urls: [
'http://nodejs.org/',
{url: 'http://nodejs.org/about', filename: 'about.html'},
{url: 'http://blog.nodejs.org/', filename: 'blog.html'}
"http://nodejs.org/",
{ url: "http://nodejs.org/about", filename: "about.html" },
{ url: "http://blog.nodejs.org/", filename: "blog.html" }
],
directory: '/path/to/save',
directory: "/path/to/save",
subdirectories: [
{directory: 'img', extensions: ['.jpg', '.png', '.svg']},
{directory: 'js', extensions: ['.js']},
{directory: 'css', extensions: ['.css']}
{ directory: "img", extensions: [".jpg", ".png", ".svg"] },
{ directory: "js", extensions: [".js"] },
{ directory: "css", extensions: [".css"] }
],
sources: [
{selector: 'img', attr: 'src'},
{selector: 'link[rel="stylesheet"]', attr: 'href'},
{selector: 'script', attr: 'src'}
{ selector: "img", attr: "src" },
{ 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'
"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) {
}).then(function(result) {
console.log(result);
}).catch(function(err){
}).catch(function(err) {
console.log(err);
});