Skip to content

[SDK] Browser Agent & Scrape

FTCHD edited this page Jul 13, 2024 · 3 revisions

Useful when you want to get contents of a website or page. This also renders the page, not just the initial HTML snippet.

Simply call the scrape function with your URL, and you will get the HTML as a string.

Function Arguments:

  • url: Required.
  • readability: If you want to process the HTML with Mozilla's Readability.
  • markdown: If you want the content returned as Markdown instead of HTML. Works together with readability.

Example

import { useFrameConfig } from '@sdk/hooks'
import type { Config } from '.'
import { scrape } from '@/lib/scrape'

export default function Inspector() {
	const [config, updateConfig] = useFrameConfig<Config>()
	
	return (
		<div className="h-full flex flex-col gap-10">
			<button
				onClick={async () => {
					const html = await scrape({ url: 'https://www.frametra.in' })
					
					updateConfig({ theContent: html })
				}}
			>
				Scrape
			</button>
		</div>
	)
}