From 72f83468299f2510ada7bb2afdc2ca841127fd24 Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Sat, 11 Nov 2023 15:10:57 +0100 Subject: Update readme --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index 19ad92c..3b9da41 100644 --- a/README.md +++ b/README.md @@ -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")) // [
  • Item 1
  • ] ``` +## Flyscrape API + +```javascript +import { parse } from "flyscrape"; + +const doc = parse(`
    bar
    `); +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: "...", + 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). -- cgit v1.2.3