Image Parsers¶
Base Image Parser¶
-
class
html2ans.parsers.image.
AbstractImageParser
[source]¶ Bases:
html2ans.parsers.base.BaseElementParser
Abstract class for image parsing.
-
construct_output
(element, *args, **kwargs)[source]¶ Convenience method for constructing an output dictionary. If element is a
Tag
with 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
type
fieldcontent (str) – the content to put in the
content
fieldversion (str) – the version to put in the
version
field. Note: if not provided butversion_required=True
on 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.AbstractImageParser
Basic 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.ImageParser
Link-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.ImageParser
Figure-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 }