This topic describes the ReadPageScrape API, which uses a headless browser to dynamically render and access target pages. This topic also covers the features, parameters, return values, and calling methods of the API.
1. API description
The features of the API are as follows:
Reads HTML and parses webpage content in a browser sandbox environment.
The API starts parsing after the resources on the target page are fully loaded. You can adjust the maximum wait time using the pageTimeout parameter. The overall API processing time is significantly affected by the resource loading status of the target site.
If the Content-Type in the response header of the target address is
application/pdf, the system automatically triggers PDF parsing. The parsed content is extracted from the PDF file displayed in the current browser window.
2. API definition
2.1 Request parameters
Field | Parameter value | Description | |
url <string> required | The target address to parse. It must start with http:// or https://. | ||
pageTimeout <int> | [0, 100000] default: 10000 | The timeout period for waiting for the target site to fully load. The API will complete within pageTimeout + 6000 ms.
| |
formats <array> | rawHtml html markdown text screenshot default: [ "html", "markdown", "text" ] | The format of the parsing result.
| |
maxAge <int> | [0, ∞] | The maximum cache time, in seconds.
| |
actions <array> | actions.type: "wait"
| [] | Executes specified operations before getting the main content.
Example: |
actions.type: "eval"
| |||
readability <map> | readabilityMode <string> | none normal article default: none | normal: Based on a proprietary algorithm, removes irrelevant information (such as headers, footers, and navigation) and returns the main content. article: Based on a proprietary algorithm, gets the main content of the site. Suitable for blogs and news sites, but not for directory or navigation pages. |
excludeAllImages <bool> | default: false | Specifies whether to remove all images. | |
excludeAllLinks <bool> | default: false | Specifies whether to remove all links. | |
excludedTags <array> | [] | Specifies the tags to exclude, such as: ["form", "header", "footer", "nav"] | |
Return parameters
Field | Field description | Example | ||
requestId <string> | The request ID. Provide this ID when troubleshooting issues. | |||
errorCode <string | null> | Error code. | |||
errorMessage <string | null> | Error message. | |||
data <map> | statusCode <int> |
| ||
rawHtml <string | null> | The original HTML of the target site. | |||
html <string | null> | The readable HTML of the target site. | |||
text <string | null> | Content in text format. | |||
markdown <string | null> | Content in markdown format. | |||
screenshot <string | null> | A screenshot of the target site. | |||
actions <array | null> | The execution results corresponding to the actions. | | ||
links <map | null> | internal <map|null> | Link information from the target URL (internal links).
| | |
external <map|null> | Link information from the target URL (external links). | |||
media <map | null> | images <map|null> | Image information from the target URL.
| | |
audios <array|null> | Audio information from the target URL.
| |||
videos <array|null> | Video information from the target URL.
| | ||
metadata <map> | url <string> | Target address. | | |
redirectedUrl | The actual URL after redirection. | |||
title <string|null> | Site title. | |||
hostLogo <string|null> | Site favicon or logo URL. | |||
lastModified <string|null> | Last modified time. | |||
publishedDate <string|null> | Published date ( | |||
contentType <string|null> | The | |||
description <string|null> | Page description ( | |||
author <string|null> | Author information ( | |||
siteName <string|null> | Site name ( | |||
imageUrl <string|null> | Main image URL ( | |||
canonicalUrl <string|null> | Canonical URL ( | |||
language <string|null> | Page language ( | |||
schemaType <string|null> | JSON-LD | |||
pageType <string|null> | ||||
pdfParse <bool> | Indicates whether PDF parsing was triggered. | |||
Error codes
HTTP Code | Error code | Error message | Solution |
404 | InvalidAccessKeyId.NotFound | Specified access key is not found. | Check and ensure that your AccessKey and Secret are correct. |
403 | Retrieval.NotActivate | Please activate AI search service | Place an order or contact your account manager to activate the service. |
403 | Retrieval.NotAuthorised | Please authorize the AliyunIQSFullAccess privilege to the sub-account. | The RAM user is not authorized. For more information, see Create a RAM user and grant permissions. |
429 | Retrieval.Throttling.User | Request was denied due to user flow control. | The rate limit was exceeded. |
429 | Retrieval.TestUserQueryPerDayExceeded | The query per day exceed the limit. | The test quota was exceeded (1000 times/30 days). |
403 | ReadPage.SecurityRestrict | Security restrictions on the target site (e.g., robots.txt). | |
400 | ReadPage.RequestTimeout | Request target url timeout. | The request timed out. Extend the timeout period as needed. |
429 | ReadPage.RateLimitByDomain | The domain has reached the rate limit. | |
500 | ReadPage.UnknownError | Unknown error. |
Additional information
1. Stealth mode
This API enables stealth mode by default. This mode optimizes the browser environment's fingerprint to more closely resemble that of a real user's browser. This improves the compatibility and stability of automated access.

2. Limitations
This API complies with the target website's robots.txt protocol, user agreements, and relevant laws and regulations.
This API only provides technical support and page parsing capabilities. We are not responsible for the generation, publication, display, or use of content from third-party websites. We make no promises or guarantees of any kind for third-party content that is scraped, accessed, or otherwise obtained through this service.
API calls
Examples
Python SDK
Prerequisites
Ensure that you have Python 3.8 or later installed.
Install the SDK
pip install alibabacloud_iqs20241111==1.6.0Sample code
import json
from Tea.exceptions import TeaException
from alibabacloud_iqs20241111 import models
from alibabacloud_iqs20241111.client import Client
from alibabacloud_tea_openapi import models as open_api_models
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Client:
config = open_api_models.Config(
# TODO: Replace with your AccessKey and Secret. We recommend loading them from environment variables.
access_key_id="$YOUR_ACCESS_KEY",
access_key_secret="$YOUR_ACCESS_SECRET"
)
config.endpoint = f"iqs.cn-zhangjiakou.aliyuncs.com"
return Client(config)
@staticmethod
def main() -> None:
client = Sample.create_client()
run_instances_request = models.ReadPageScrapeRequest(
body=models.ReadPageScrapeBody(
url="http://www.example.com",
max_age=0,
)
)
try:
response = client.read_page_scrape(run_instances_request)
print(f"API call successful. request_id: {response.body.request_id}, result: ")
print(f"{json.dumps(response.body.data.to_map(), indent=2)}")
except TeaException as e:
request_id = e.data.get("requestId")
code = e.data.get("errorCode")
message = e.data.get("errorMessage")
print(f"API call failed. requestId: {request_id}, code: {code}, message: {message}")
if __name__ == "__main__":
Sample.main()
Java SDK
Prerequisites
Ensure that you have Java 8 or later installed.
Maven dependency
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>iqs20241111</artifactId>
<version>1.6.0</version>
</dependency>Sample code
package com.aliyun.iqs.readpage.example;
import com.aliyun.iqs20241111.Client;
import com.aliyun.iqs20241111.models.*;
import com.aliyun.teaopenapi.models.Config;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class Example {
public static void main(String[] args) throws Exception {
Client client = initClient();
invoke(client, "http://www.example.com");
}
private static Client initClient() throws Exception {
// TODO: Replace with your AccessKey and Secret. We recommend loading them from environment variables.
String accessKeyId = "$YOUR_ACCESS_KEY";
String accessKeySecret = "$YOUR_ACCESS_SECRET";
Config config = new Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
config.setEndpoint("iqs.cn-zhangjiakou.aliyuncs.com");
return new Client(config);
}
private static void invoke(Client client, String url) {
ReadPageScrapeBody input = new ReadPageScrapeBody();
input.setUrl(url);
ReadPageScrapeRequest request = new ReadPageScrapeRequest().setBody(input);
try {
ReadPageScrapeResponse response = client.readPageScrape(request);
printOutput(response.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
private static void printOutput(ReadPageBasicResponseBody output) {
// Create a Gson instance with pretty printing using GsonBuilder.
Gson gson = new GsonBuilder()
.setPrettyPrinting()
.disableHtmlEscaping()
.create();
// Print the formatted JSON.
String prettyJson = gson.toJson(output);
System.out.println(prettyJson);
}
}
Go SDK
Prerequisites
Ensure that you have Go 1.10.x or later installed.
Install the SDK
require (
github.com/alibabacloud-go/iqs-20241111 v1.6.0
)
Sample code
package main
import (
"fmt"
"log"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
iqs20241111 "github.com/alibabacloud-go/iqs-20241111/client"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea"
)
const endpointURL = "iqs.cn-zhangjiakou.aliyuncs.com"
func createClient() (*iqs20241111.Client, error) {
// TODO: Replace with your AccessKey and Secret.
accessKeyID := "YOUR_ACCESS_KEY"
accessKeySecret := "YOUR_ACCESS_SECRET"
if accessKeyID == "" || accessKeySecret == "" {
return nil, fmt.Errorf("ACCESS_KEY or ACCESS_SECRET environment variable is not set")
}
config := &openapi.Config{
AccessKeyId: tea.String(accessKeyID),
AccessKeySecret: tea.String(accessKeySecret),
Endpoint: tea.String(endpointURL),
}
return iqs20241111.NewClient(config)
}
func runReadPage(client *iqs20241111.Client) error {
body := &iqs20241111.ReadPageScrapeBody{
Url: tea.String("http://www.example.com"),
}
request := &iqs20241111.ReadPageScrapeRequest{
body,
}
runtime := &util.RuntimeOptions{}
resp, err := client.ReadPageScrapeWithOptions(request, nil, runtime)
if err != nil {
return fmt.Errorf("readpage failed: %w", err)
}
fmt.Printf("[%s] response: %s\n", *resp.Body.RequestId, resp.Body)
return nil
}
func main() {
client, err := createClient()
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
if err := runReadPage(client); err != nil {
log.Fatalf("Error running readpage: %v", err)
}
}
HTTP call
Request parameters (Request Body)
curl --location "https://cloud-iqs.aliyuncs.com/readpage/scrape" \
--header "Content-Type: application/json" \
--header "X-API-Key: <YOUR-IQS-API-KEY>" \
--data '{
"url": "https://www.example.com",
"maxAge": 0
}'Back
{
"data": {
"html": "<html>\n<head><title>Example Domain</title></head>\n<body>\n<div>\n<h1>Example Domain</h1>\n<p>This domain is for use in documentation examples without needing permission. Do not use it in operations.</p>\n<p><a href=\"https://iana.org/domains/example\">Learn more</a></p>\n</div>\n</body>\n</html>",
"links": {
"internal": "[]",
"external": "[{\"href\":\"https://iana.org/domains/example\",\"text\":\"Learn more\",\"title\":\"\"}]"
},
"markdown": "# Example Domain\nThis domain is for use in documentation examples without needing permission. Do not use it in operations.\n[Learn more](https://iana.org/domains/example)\n",
"media": {
"images": "[]",
"audios": "[]",
"videos": "[]"
},
"metadata": {
"hostname": "www.example.com",
"pdfParse": false,
"title": "Example Domain",
"url": "https://www.example.com"
},
"statusCode": 200,
"text": "# Example Domain\nThis domain is for use in documentation examples without needing permission. Do not use it in operations.\nLearn more\n"
},
"requestId": "1d0ac13a-8c73-4134-a835-35d0126f733c"
}