summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRafi Ramadhana <42462215+rafiramadhana@users.noreply.github.com>2023-11-23 18:58:41 +0700
committerGitHub <noreply@github.com>2023-11-23 12:58:41 +0100
commitcbdbbd249239345f88bea031beb55e84c2f47688 (patch)
treef3b001d36c0da83a1827eb8008615f5f2577a638 /examples
parent13322edf37510b6d3bb68a853368fd1a0a67a105 (diff)
Add custom request header (#18)
Diffstat (limited to 'examples')
-rw-r--r--examples/custom_headers.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/custom_headers.js b/examples/custom_headers.js
new file mode 100644
index 0000000..6435a39
--- /dev/null
+++ b/examples/custom_headers.js
@@ -0,0 +1,26 @@
+export const config = {
+ url: "https://news.ycombinator.com/",
+ headers: {
+ "Authorization": "Basic ZGVtbzpwQDU1dzByZA==",
+ "User-Agent": "Gecko/1.0",
+ }
+};
+
+export default function({ doc, absoluteURL }) {
+ const posts = doc.find(".athing");
+
+ return {
+ posts: posts.map((post) => {
+ const link = post.find(".titleline > a");
+ const meta = post.next();
+
+ return {
+ url: absoluteURL(link.attr("href")),
+ user: meta.find(".hnuser").text(),
+ title: link.text(),
+ points: meta.find(".score").text().replace(" points", ""),
+ created: meta.find(".age").attr("title"),
+ };
+ }),
+ };
+}