// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../resource';
import * as Core from '../../core';
export class Scrape extends APIResource {
/**
* Get meta attributes like height, width, text and others of selected elements.
*
* @example
* ```ts
* const scrapes = await client.browserRendering.scrape.create(
* {
* account_id: 'account_id',
* elements: [{ selector: 'h1' }],
* html: '
Hello World!
',
* },
* );
* ```
*/
create(params: ScrapeCreateParams, options?: Core.RequestOptions): Core.APIPromise {
const { account_id, cacheTTL, ...body } = params;
return (
this._client.post(`/accounts/${account_id}/browser-rendering/scrape`, {
query: { cacheTTL },
body,
...options,
}) as Core.APIPromise<{ result: ScrapeCreateResponse }>
)._thenUnwrap((obj) => obj.result);
}
}
export type ScrapeCreateResponse = Array;
export namespace ScrapeCreateResponse {
export interface ScrapeCreateResponseItem {
results: ScrapeCreateResponseItem.Results;
/**
* Selector.
*/
selector: string;
}
export namespace ScrapeCreateResponseItem {
export interface Results {
attributes: Array;
/**
* Element height.
*/
height: number;
/**
* HTML content.
*/
html: string;
/**
* Element left.
*/
left: number;
/**
* Text content.
*/
text: string;
/**
* Element top.
*/
top: number;
/**
* Element width.
*/
width: number;
}
export namespace Results {
export interface Attribute {
/**
* Attribute name.
*/
name: string;
/**
* Attribute value.
*/
value: string;
}
}
}
}
export type ScrapeCreateParams = ScrapeCreateParams.Variant0 | ScrapeCreateParams.Variant1;
export declare namespace ScrapeCreateParams {
export interface Variant0 {
/**
* Path param: Account ID.
*/
account_id: string;
/**
* Body param
*/
elements: Array;
/**
* Body param: Set the content of the page, eg: `Hello World!!
`. Either
* `html` or `url` must be set.
*/
html: string;
/**
* Query param: Cache TTL default is 5s. Set to 0 to disable.
*/
cacheTTL?: number;
/**
* Body param: The maximum duration allowed for the browser action to complete
* after the page has loaded (such as taking screenshots, extracting content, or
* generating PDFs). If this time limit is exceeded, the action stops and returns a
* timeout error.
*/
actionTimeout?: number;
/**
* Body param: Adds a `