-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'issue-193-type-error' of github.com:fadingNA/scrape-it …
…into new-version
- Loading branch information
Showing
5 changed files
with
680 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"use strict"; | ||
|
||
import scrapeIt from "../lib"; | ||
|
||
// Promise interface | ||
scrapeIt("https://ionicabizau.net", { | ||
title: ".header h1" | ||
, desc: ".header h2" | ||
, avatar: { | ||
selector: ".header img" | ||
, attr: "src" | ||
} | ||
}).then(({ data, status }) => { | ||
console.log(`Status Code: ${status}`) | ||
console.log(data) | ||
}); | ||
|
||
// Async-Await | ||
(async () => { | ||
const { data } = await scrapeIt("https://ionicabizau.net", { | ||
// Fetch the articles | ||
articles: { | ||
listItem: ".article" | ||
, data: { | ||
// Get the article date and convert it into a Date object | ||
createdAt: { | ||
selector: ".date" | ||
, convert: x => new Date(x) | ||
} | ||
// Get the title | ||
, title: "a.article-title" | ||
// Nested list | ||
, tags: { | ||
listItem: ".tags > span", | ||
} | ||
// Get the content | ||
, content: { | ||
selector: ".article-content" | ||
, how: "html", | ||
} | ||
// Get attribute value of root listItem by omitting the selector | ||
, classes: { | ||
attr: "class" | ||
} | ||
} | ||
} | ||
// Fetch the blog pages | ||
, pages: { | ||
listItem: "li.page" | ||
, data: { | ||
title: "a" | ||
, url: { | ||
selector: "a" | ||
, attr: "href" | ||
} | ||
} | ||
} | ||
// Fetch some other data from the page | ||
, title: ".header h1" | ||
, desc: ".header h2" | ||
, avatar: { | ||
selector: ".header img" | ||
, attr: "src" | ||
} | ||
}) | ||
//console.log(data); | ||
})(); | ||
|
||
|
||
|
||
(() => { | ||
const { data } = scrapeIt.scrapeHTML<{data: unknown}>("https://ionicabizau.net", { | ||
data: { | ||
listItem: 'main' | ||
, data: { | ||
items:{ | ||
selector: 'article' | ||
, how: (element) => { | ||
const $items = element.find('p:nth-child(n+2)') | ||
return $items.text() | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
console.log(data) | ||
}) |
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
Oops, something went wrong.