> ## Documentation Index
> Fetch the complete documentation index at: https://docs.context.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Ruby

> Install the Ruby SDK, scrape a webpage, and retrieve brand data.

The [Ruby SDK](https://rubygems.org/gems/context.dev) requires Ruby 3.2 or newer.

## Install the SDK

```bash theme={null}
gem install context.dev
```

## Set your API key

Get a secret API key from the [dashboard](https://context.dev/dashboard). Set it in the terminal where you will run the example:

```bash theme={null}
export CONTEXT_DEV_API_KEY="ctxt_secret_..."
```

Keep the key in server-side code. Do not expose it in a browser or commit it to source control.

## Scrape a webpage

Save this as `scrape.rb`:

```ruby scrape.rb theme={null}
require "cgi/core"
require "context_dev"

client = ContextDev::Client.new(
  api_key: ENV.fetch("CONTEXT_DEV_API_KEY")
)

response = client.web.web_scrape_md(
  url: "https://example.com",
  use_main_content_only: true,
)

puts response.markdown
```

Run it with the Ruby installation used above:

```bash theme={null}
ruby scrape.rb
```

If your project has a `Gemfile`, add `gem "context.dev"`, run `bundle install`, and use `bundle exec ruby scrape.rb`.

## Check the result

The example prints the page content as Markdown. Look for the `Example Domain` heading; the remaining text and formatting may vary.

```markdown Expected heading theme={null}
# Example Domain
```

If you receive an error, check the key and request details in [Troubleshooting](/optimization/troubleshooting). See the [Markdown API reference](/api-reference/web-scraping/markdown) for all parameters and response fields.

## Retrieve brand data

Replace the request and final `puts` with this lookup. It prints the matched company name.

```ruby theme={null}
response = client.brand.retrieve(
  body: { type: :by_domain, domain: "stripe.com" }
)

puts response.brand.title
```

## Next steps

<CardGroup cols={2}>
  <Card title="Scrape a webpage" icon="globe" href="/guides/scrape-websites-to-markdown">
    Choose which page content to include.
  </Card>

  <Card title="Retrieve brand data" icon="palette" href="/guides/get-brand-data">
    Look up profiles with other company identifiers.
  </Card>
</CardGroup>
