pub struct JsonLdExtractor;Expand description
Extracts Schema.org structured data from JSON-LD <script> tags.
§Examples
use schemaorg_rs::extraction::{Extractor, JsonLdExtractor};
let html = r#"<html><head>
<script type="application/ld+json">{
"@context": "https://schema.org",
"@type": "Product",
"name": "Widget"
}</script>
</head></html>"#;
let output = JsonLdExtractor.extract(html).unwrap();
assert_eq!(output.nodes[0].types, vec!["Product"]);Implementations§
Source§impl JsonLdExtractor
impl JsonLdExtractor
Sourcepub fn extract_from_document(
&self,
document: &Html,
html: &str,
) -> Result<ExtractionOutput, ExtractionError>
pub fn extract_from_document( &self, document: &Html, html: &str, ) -> Result<ExtractionOutput, ExtractionError>
Extracts from an already-parsed document.
The raw html string is needed for source-location computation
(finding byte offsets of <script> tags).
§Errors
Returns ExtractionError if a fatal error prevents extraction.
JSON parse failures are captured as warnings, not errors.
§Panics
Panics if the internal CSS selector constant fails to parse. This is a compile-time-verified string and will never fail.
Trait Implementations§
Source§impl Extractor for JsonLdExtractor
impl Extractor for JsonLdExtractor
Source§fn extract(&self, html: &str) -> Result<ExtractionOutput, ExtractionError>
fn extract(&self, html: &str) -> Result<ExtractionOutput, ExtractionError>
Extracts structured data nodes from an HTML document. Read more
Auto Trait Implementations§
impl Freeze for JsonLdExtractor
impl RefUnwindSafe for JsonLdExtractor
impl Send for JsonLdExtractor
impl Sync for JsonLdExtractor
impl Unpin for JsonLdExtractor
impl UnsafeUnpin for JsonLdExtractor
impl UnwindSafe for JsonLdExtractor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more