Image Parsers¶
Base Image Parser¶
-
class
html2ans.parsers.image.AbstractImageParser[source]¶ Bases:
html2ans.parsers.base.BaseElementParserAbstract class for image parsing.
-
construct_output(element, *args, **kwargs)[source]¶ Convenience method for constructing an output dictionary. If element is a
Tagwith attributes, those attributes will be stashed inadditional_properties.- Parameters
element (bs4.element.Tag or bs4.element.Comment or bs4.element.NavigableString) – the element being parsed
ans_type (str) – the ANS type to put in the output
typefieldcontent (str) – the content to put in the
contentfieldversion (str) – the version to put in the
versionfield. Note: if not provided butversion_required=Trueon this parser, the output will receive a version from the root parser
-
Basic Image Parser¶
-
class
html2ans.parsers.image.ImageParser[source]¶ Bases:
html2ans.parsers.image.AbstractImageParserBasic img element parser.
Example:
<img src="postreports.jpg" alt="The Post Reports" width="50" height="50" />
->
{ "type": "image", "version": "0.8.0", "url": "postreports.jpg", "caption": "The Post Reports", "width": 50, "height": 50 }
Linked Image Parser¶
-
class
html2ans.parsers.image.LinkedImageParser[source]¶ Bases:
html2ans.parsers.image.ImageParserLink-wrapped image parser.
Example:
<a href="https://www.stitcher.com/podcast/the-washington-post/post-reports"> <img src="postreports.jpg" alt="The Post Reports" width="50" height="50" /> </a>
->
{ "type": "image", "version": "0.8.0", "url": "postreports.jpg", "caption": "The Post Reports", "width": 50, "height": 50, "additional_properties": { "image_link": "https://www.stitcher.com/podcast/the-washington-post/post-reports" } }
Figure Parser¶
-
class
html2ans.parsers.image.FigureParser[source]¶ Bases:
html2ans.parsers.image.ImageParserFigure-wrapped image parser.
Example:
<figure> <img src="postreports.jpg" alt="The Post Reports logo" width="50" height="50" /> <figcaption>The Post Reports</figcaption> </figure>
->
{ "type": "image", "version": "0.8.0", "url": "postreports.jpg", "caption": "The Post Reports", "width": 50, "height": 50 }