Setting cookies
Cookies can be passed as array in cookies
parameter.
Remember to encode this parameter like in the examples below.
Cookies syntax
Cookies is an array of objects.
"name"
and "value"
are required fields, other are optional.
Example array with two cookies:
[
{
"name": "cookie1",
"value": "cookie1value"
},
{
"name": "cookie2",
"value": "cookie2value",
"domain": "example.com",
"path": "/",
"expires": 100000,
"secure": true,
"httpOnly": false,
"sameSite": "Lax"
}
]
name
Required string. Cookie's name.
value
Required string. Cookie's value.
domain
Optional string. Cookie's domain.
You can either set domain
and path
or url
.
If you don't set any of the three, we use domain equal to the domain of the desired URL and path to /
.
For example, if you scrape https://example.com/some/path?arg1=value1&arg2=value2
and don't specify cookie's URL, domain nor path, then cookie will have its domain
set to example.com
and path to /
.
See more info on MDN.
path
Optional string. Cookie's path.
You can either set domain
and path
or url
.
If you don't set any of the three, we use domain equal to the domain of the desired URL and path to /
.
For example, if you scrape https://example.com/some/path?arg1=value1&arg2=value2
and don't specify cookie's URL, domain nor path, then cookie will have its domain
set to example.com
and path to /
.
See more info on MDN.
url
Optional string. Cookie's URL.
You can either set domain
and path
or url
.
If you don't set any of the three, we use domain equal to the domain of the desired URL and path to /
.
For example, if you scrape https://example.com/some/path?arg1=value1&arg2=value2
and don't specify cookie's URL, domain nor path, then cookie will have its domain
set to example.com
and path to /
.
See more info on MDN.
expires
Optional integer. Cookie's expiry timestamp.
Specifies cookie lifetime in Unix time in seconds. See more info about cookie's lifetime on MDN.
secure
Optional boolean.
See more info on MDN.
httpOnly
Optional boolean.
See more info on MDN.
sameSite
Optional string. One of "Strict"
, "Lax"
, or "None"
.
Example
The following example sets two cookies:
- cookie1-name:
cookie1-value
, - cookie2-name:
cookie2-value
.
- Python
- NodeJS
- cURL
import requests
import json
payload = {
"api_key": "[your API key]",
"url": "https://example.com",
"cookies": json.dumps(
[
{"name": "cookie1-name", "value": "cookie1-value"},
{"name": "cookie2-name", "value": "cookie2-value"},
]
),
}
response = requests.get("https://scraping.narf.ai/api/v1/", params=payload)
print(response.content)
const axios = require("axios");
const payload = {
api_key: "[your API key]",
url: "https://example.com",
cookies: JSON.stringify(
[
{name: "cookie1-name", value: "cookie1-value"},
{name: "cookie2-name", value: "cookie2-value"},
]
),
};
const response = await axios.get("https://scraping.narf.ai/api/v1/", { params: payload });
console.log(response.data);
curl -G --data-urlencode 'url=https://example.com' \
--data-urlencode 'cookies=[{"name": "cookie1-name", "value": "cookie1-value"}, {"name": "cookie2-name", "value": "cookie2-value"}]' \
'https://scraping.narf.ai/api/v1/?api_key=[your API key]'