Skip to content

Commit 7312544

Browse files
author
stlc-bot
committed
feat(scrape): add CSS extraction rules to HTML scraping (#1146)
Stainless-Generated-From: c9a2aa88567a8fb4c0050459dd1822c5f7047bab
1 parent 29338a1 commit 7312544

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎pkg/cmd/web.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ var webWebScrapeBytes = requestflag.WithInnerFlags(cli.Command{
804804

805805
var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{
806806
Name: "web-scrape-html",
807-
Usage: "Scrapes the given URL and returns the raw HTML content of the page. The base\nrequest costs 1 credit; requests with browser actions cost 2 credits. A request\nthat hits its timeoutOpts.milliseconds deadline fails with 408 and is not\nbilled, unless timeoutOpts.behavior=return-partial is set — then the page as\nrendered so far is returned with `finalDOMState: \"still-loading\"` and billed at\nthe base cost of 1 credit.",
807+
Usage: "Scrapes the given URL and returns the HTML content of the page. Optional\nextractRules return deterministic structured data in extracted using CSS\nselectors, attributes, lists, and nested rules, without an LLM or additional\ncredits. Rules run on the returned HTML after selector and main-content\nfiltering. Send extractRules as a JSON-encoded query parameter. The base request\ncosts 1 credit; requests with browser actions cost 2 credits. A request that\nhits its timeoutOpts.milliseconds deadline fails with 408 and is not billed,\nunless timeoutOpts.behavior=return-partial is set — then the page as rendered so\nfar is returned with `finalDOMState: \"still-loading\"` and billed at the base\ncost of 1 credit.",
808808
Suggest: true,
809809
Flags: []cli.Flag{
810810
&requestflag.Flag[string]{
@@ -828,6 +828,11 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{
828828
Usage: `CSS selectors to remove from the result. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]".`,
829829
QueryPath: "excludeSelectors",
830830
},
831+
&requestflag.Flag[map[string]any]{
832+
Name: "extract-rules",
833+
Usage: `Optional CSS extraction rules applied to the returned HTML after selector and main-content filtering. Use selector strings ("h1", "a@href") or objects with selector, type (item or list), and output (text, html, @attribute, or nested rules). Text whitespace is normalized; html includes the matched element; attributes are returned as written. Missing items are null and missing lists are empty. CSS only; XPath is not supported. Maximum: 100 fields across 5 levels. Send a JSON-encoded string in the extractRules query parameter.`,
834+
QueryPath: "extractRules",
835+
},
831836
&requestflag.Flag[map[string]any]{
832837
Name: "headers",
833838
Usage: "Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache.",

‎pkg/cmd/web_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ func TestWebWebScrapeHTML(t *testing.T) {
587587
"--action", "[{do: wait, timeMs: 0}]",
588588
"--country", "de",
589589
"--exclude-selector", "[x]",
590+
"--extract-rules", "{foo: x}",
590591
"--headers", "{foo: J!}",
591592
"--include-frames=true",
592593
"--include-selector", "[x]",
@@ -615,6 +616,7 @@ func TestWebWebScrapeHTML(t *testing.T) {
615616
"--action", "[{do: wait, timeMs: 0}]",
616617
"--country", "de",
617618
"--exclude-selector", "[x]",
619+
"--extract-rules", "{foo: x}",
618620
"--headers", "{foo: J!}",
619621
"--include-frames=true",
620622
"--include-selector", "[x]",

0 commit comments

Comments
 (0)