Skip to main content

data_for_seo/entity/on_page/
content_parsing.rs

1use crate::entity::OnPageDataApiCrawlStatus;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5/// OnPage Content Parsing result: structured content extracted from a page.
6/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
7#[derive(Debug, Default, Serialize, Deserialize, Clone)]
8pub struct OnPageDataApiContentParsing {
9    /// Status of the crawling session (`in_progress`, `finished`).
10    pub crawl_progress: Option<String>,
11    /// Details of the crawling session.
12    pub crawl_status: Option<OnPageDataApiCrawlStatus>,
13    /// Number of items in the `items` array.
14    pub items_count: Option<i64>,
15    /// Array of parsed pages.
16    pub items: Option<Vec<OnPageDataApiContentParsingItem>>,
17}
18
19/// A single parsed page in a Content Parsing result.
20/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
21#[derive(Debug, Default, Serialize, Deserialize, Clone)]
22pub struct OnPageDataApiContentParsingItem {
23    /// Item type; `content_parsing_element`.
24    #[serde(rename = "type")]
25    pub item_type: Option<String>,
26    /// Date and time when the content was fetched, in UTC.
27    pub fetch_time: Option<String>,
28    /// HTTP response code of the parsed page.
29    pub status_code: Option<i32>,
30    /// Structured page content organized by section.
31    pub page_content: Option<OnPageDataApiPageContent>,
32    /// Page content rendered as Markdown; returned only when `markdown_view` is enabled.
33    pub page_as_markdown: Option<String>,
34}
35
36/// Structured page content grouped by section.
37/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
38#[derive(Debug, Default, Serialize, Deserialize, Clone)]
39pub struct OnPageDataApiPageContent {
40    /// Content of the page header section.
41    pub header: Option<OnPageDataApiContentSection>,
42    /// Content of the page footer section.
43    pub footer: Option<OnPageDataApiContentSection>,
44    /// Main topics identified on the page.
45    pub main_topic: Option<Vec<OnPageDataApiContentTopic>>,
46    /// Secondary topics identified on the page.
47    pub secondary_topic: Option<Vec<OnPageDataApiContentTopic>>,
48    /// Rating information for products displayed on the page.
49    pub ratings: Option<Vec<OnPageDataApiContentRating>>,
50    /// Products displayed on the page.
51    pub offers: Option<Vec<OnPageDataApiContentOffer>>,
52    /// Comments displayed on the page.
53    pub comments: Option<Vec<OnPageDataApiContentComment>>,
54    /// Contact information displayed on the page.
55    pub contacts: Option<OnPageDataApiContentContacts>,
56}
57
58/// A content section (header or footer) with its primary, secondary, and table content.
59/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
60#[derive(Debug, Default, Serialize, Deserialize, Clone)]
61pub struct OnPageDataApiContentSection {
62    /// Primary content elements of the section.
63    pub primary_content: Option<Vec<OnPageDataApiContentElement>>,
64    /// Secondary content elements of the section.
65    pub secondary_content: Option<Vec<OnPageDataApiContentElement>>,
66    /// Tables found in the section.
67    pub table_content: Option<Vec<OnPageDataApiContentTable>>,
68}
69
70/// A topic block on the page with its metadata and content.
71/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
72#[derive(Debug, Default, Serialize, Deserialize, Clone)]
73pub struct OnPageDataApiContentTopic {
74    /// Meta title of the topic block.
75    pub h_title: Option<String>,
76    /// Main title of the block.
77    pub main_title: Option<String>,
78    /// Author of the content.
79    pub author: Option<String>,
80    /// Language of the content.
81    pub language: Option<String>,
82    /// HTML heading level of the block.
83    pub level: Option<String>,
84    /// Primary content elements of the topic.
85    pub primary_content: Option<Vec<OnPageDataApiContentElement>>,
86    /// Secondary content elements of the topic.
87    pub secondary_content: Option<Vec<OnPageDataApiContentElement>>,
88    /// Tables found in the topic.
89    pub table_content: Option<Vec<OnPageDataApiContentTable>>,
90}
91
92/// A single content element, optionally carrying link URLs.
93/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
94#[derive(Debug, Default, Serialize, Deserialize, Clone)]
95pub struct OnPageDataApiContentElement {
96    /// Text of the content element.
97    pub text: Option<String>,
98    /// Page URL displayed when the text is a link anchor.
99    pub url: Option<String>,
100    /// Additional URLs and anchors within the element.
101    pub urls: Option<Vec<OnPageDataApiContentUrl>>,
102}
103
104/// A hyperlink with its anchor text.
105/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
106#[derive(Debug, Default, Serialize, Deserialize, Clone)]
107pub struct OnPageDataApiContentUrl {
108    /// Link destination URL.
109    pub url: Option<String>,
110    /// Anchor text of the URL.
111    pub anchor_text: Option<String>,
112}
113
114/// A parsed table with its header, body, and footer rows.
115/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
116#[derive(Debug, Default, Serialize, Deserialize, Clone)]
117pub struct OnPageDataApiContentTable {
118    /// Header rows of the table.
119    pub header: Option<Vec<Value>>,
120    /// Body rows of the table.
121    pub body: Option<Vec<Value>>,
122    /// Footer rows of the table.
123    pub footer: Option<Vec<Value>>,
124}
125
126/// Rating information for a product displayed on the page.
127/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
128#[derive(Debug, Default, Serialize, Deserialize, Clone)]
129pub struct OnPageDataApiContentRating {
130    /// Rating identifier (often `null`).
131    pub name: Option<String>,
132    /// Numeric rating value.
133    pub rating_value: Option<f64>,
134    /// Maximum possible rating value.
135    pub max_rating_value: Option<f64>,
136    /// Number of ratings received.
137    pub rating_count: Option<i64>,
138    /// Normalized rating score, from 0 to 1.
139    pub relative_rating: Option<f64>,
140}
141
142/// A product offer displayed on the page.
143/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
144#[derive(Debug, Default, Serialize, Deserialize, Clone)]
145pub struct OnPageDataApiContentOffer {
146    /// Name of the product.
147    pub name: Option<String>,
148    /// Price of the product.
149    pub price: Option<f64>,
150    /// Currency code for the price.
151    pub price_currency: Option<String>,
152    /// Date and time until which the price is valid.
153    pub price_valid_until: Option<String>,
154}
155
156/// A comment displayed on the page.
157/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
158#[derive(Debug, Default, Serialize, Deserialize, Clone)]
159pub struct OnPageDataApiContentComment {
160    /// Rating attached to the comment.
161    pub rating: Option<OnPageDataApiContentRating>,
162    /// Title of the comment.
163    pub title: Option<String>,
164    /// Date the comment was published.
165    pub publish_date: Option<String>,
166    /// Author of the comment.
167    pub author: Option<String>,
168    /// Text of the comment, with any URLs.
169    pub primary_content: Option<Vec<OnPageDataApiContentElement>>,
170}
171
172/// Contact information displayed on the page.
173/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
174#[derive(Debug, Default, Serialize, Deserialize, Clone)]
175pub struct OnPageDataApiContentContacts {
176    /// Telephone numbers found on the page.
177    pub telephones: Option<Vec<String>>,
178    /// Email addresses found on the page.
179    pub emails: Option<Vec<String>>,
180}