diff options
| author | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-11-11 15:10:57 +0100 |
|---|---|---|
| committer | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-11-11 15:10:57 +0100 |
| commit | 72f83468299f2510ada7bb2afdc2ca841127fd24 (patch) | |
| tree | cf37b98488db9508a9c20443916749e638a9b045 /README.md | |
| parent | 36374b85df94bdd82f506477fefe345a24137df3 (diff) | |
Update readmev0.4.0
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -130,6 +130,11 @@ export const config = { cache: "file", // Enable file-based request caching. (default = no cache) }; +export function setup() { + // Optional setup function, called once before scraping starts. + // Can be used for authentication. +} + export default function ({ doc, url, absoluteURL }) { // doc - Contains the parsed HTML document // url - Contains the scraped URL @@ -169,6 +174,44 @@ items.map(item => item.text()) // ["Item 1", "Item 2", "Item 3"] items.filter(item => item.hasClass("a")) // [<li class="a">Item 1</li>] ``` +## Flyscrape API + +```javascript +import { parse } from "flyscrape"; + +const doc = parse(`<div class="foo">bar</div>`); +const text = doc.find(".foo").text(); +``` + +```javascript +import http from "flyscrape/http"; + +const response = http.get("https://example.com") + +const response = http.postForm("https://example.com", { + "username": "foo", + "password": "bar", +}) + +const response = http.postJSON("https://example.com", { + "username": "foo", + "password": "bar", +}) + +// Contents of response +{ + body: "<html>...</html>", + status: 200, + headers: { + "Content-Type": "text/html", + // ... + }, + error": "", +} +``` + + + ## Issues and Suggestions If you encounter any issues or have suggestions for improvement, please [submit an issue](https://github.com/philippta/flyscrape/issues). |