Embed Parsers

class html2ans.parsers.embeds.AbstractEmbedParser[source]

Bases: html2ans.parsers.base.BaseElementParser

Abstract class for embed parsing.

Reference ANS schema

Oembed response ANS schema

regex = ''

A regex that can be used to find the embed’s ID

tag = None

The tag the embed URL will appear in

attr = None

The attribute the embed URL will appear in

embed_type = None

The embed type (for populating referent.type)

provider = ''

A URL from the embed can be accessed from (given the embed’s ID)

parse(element, *args, **kwargs)[source]

Parses the given element.

Parameters

element (bs4.element.Tag or bs4.element.Comment or bs4.element.NavigableString) – the element to parse

class html2ans.parsers.embeds.DailyMotionEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

DailyMotion video parser.

Example:

<iframe src="https://www.dailymotion.com/embed/video/x2p99yn"></iframe>

->

{
    "type": "reference",
    "referent": {
        "id": "x2p99yn",
        "type": "dailymotion",
        "provider": "https://www.dailymotion.com/services/oembed?id=",
        "service": "oembed"
    }
}
class html2ans.parsers.embeds.FlickrEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

Flickr embed parser.

Example:

<a data-flickr-embed="true" href="https://www.flickr.com/photos/16177003@N03/8240338083/in/photolist-dyaTqx" title="Fox">
    <img src="https://farm9.staticflickr.com/8066/8240338083_938cc14c6f_k.jpg" width="2048" height="1272" alt="Fox">
</a><script async src="//embedr.flickr.com/assets/client-code.js" charset="utf-8"></script>

->

{
    "type": "reference",
    "referent": {
        "id": "https://www.flickr.com/photos/16177003@N03/8240338083/in/photolist-dyaTqx",
        "type": "flickr",
        "provider": "https://www.flickr.com/services/oembed.json/?url=",
        "service": "oembed"
    }
}
class html2ans.parsers.embeds.RedditEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

Reddit embed parser.

Example:

<blockquote class="reddit-card" data-card-created="1549834040">
    <a href="https://www.reddit.com/r/programming/comments/6l689j/a_manually_curated_list_of_240_popular/">
        A manually curated list of 240+ popular programming podcast episodes
    </a> from <a href="http://www.reddit.com/r/programming">r/programming</a>
</blockquote>
<script async src="//embed.redditmedia.com/widgets/platform.js" charset="UTF-8"></script>

->

{
    "type": "reference",
    "referent": {
        "id": "https://www.reddit.com/r/programming/comments/6l689j/a_manually_curated_list_of_240_popular/",
        "type": "reddit",
        "provider": "https://www.reddit.com/oembed?url=",
        "service": "oembed"
    }
}
class html2ans.parsers.embeds.PollDaddyEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

PollDaddy embed parser.

Example:

<noscript>
    <b>Click here to see this poll: <a href="https://poll.fm/6514633">https://poll.fm/6514633</a></b>
</noscript>

->

{
    "type": "reference",
    "referent": {
        "id": "https://poll.fm/6514633",
        "type": "polldaddy",
        "provider": "https://polldaddy.com/oembed/?url=",
        "service": "oembed"
    }
}
class html2ans.parsers.embeds.TwitterTweetEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

Twitter post parser.

Example:

<blockquote class="twitter-tweet" data-lang="en">
    <p lang="en" dir="ltr">
        Displaced by Woolsey fire, Malibu families gather for a meal and hugs:
        <a href="https://t.co/W3ZWJIKOjG">https://t.co/W3ZWJIKOjG</a>
        <a href="https://t.co/FUouJS6xwl">pic.twitter.com/FUouJS6xwl</a>
    </p>
    Los Angeles Times (@latimes)
    <a href="https://twitter.com/latimes/status/1065323995959037953?ref_src=twsrc%5Etfw">November 21, 2018</a>
</blockquote>

->

{
    "type": "reference",
    "referent": {
        "id": 1065323995959037953,
        "type": "twitter",
        "provider": "https://api.twitter.com/1.1/statuses/oembed.json?id=",
        "service": "oembed"
    },
    "additional_properties": {
        "class": "twitter-tweet",
        "data-lang": "en"
    }
}
class html2ans.parsers.embeds.TwitterVideoEmbedParser[source]

Bases: html2ans.parsers.embeds.TwitterTweetEmbedParser

Twitter video parser.

Example:

<blockquote class="twitter-video" data-lang="de">
    <p lang="de" dir="ltr">
        Am Sonntag wird in Hannover gefeiert!

        <a href="https://twitter.com/hashtag/Einschulung?src=hash&amp;ref_src=twsrc%5Etfw">
            #Einschulung
        </a>
        <a href="https://twitter.com/hashtag/HAZfest?src=hash&amp;ref_src=twsrc%5Etfw">
            #HAZfest
        </a>
        <a href="https://twitter.com/hashtag/AktionSichererSchulweg?src=hash&amp;ref_src=twsrc%5Etfw">
            #AktionSichererSchulweg
        </a>
        <a href="https://t.co/8q7hHjy1zK">
            pic.twitter.com/8q7hHjy1zK
        </a>
    </p>
    &mdash; HAZ (@HAZ)
    <a href="https://twitter.com/HAZ/status/1027958659404521475?ref_src=twsrc%5Etfw">August 10, 2018</a>
</blockquote>

->

{
    "type": "reference",
    "referent": {
        "id": 1027958659404521475,
        "type": "twitter",
        "provider": "https://api.twitter.com/1.1/statuses/oembed.json?id=",
        "service": "oembed"
    },
    "additional_properties": {
        "class": "twitter-video",
        "data-lang": "de"
    }
}
class html2ans.parsers.embeds.InstagramEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

Instagram embed parser.

Example:

<blockquote class="instagram-media" data-instgrm-permalink="https://www.instagram.com/p/BqTW3VBDl2c/?utm_source=ig_embed&amp;utm_medium=loading" data-instgrm-version="12">
    <div>
        <a href="https://www.instagram.com/p/BqTW3VBDl2c/?utm_source=ig_embed&amp;utm_medium=loading" target="_blank">
            Removed stuff
        </a>
        <p>
            <a href="https://www.instagram.com/p/BqTW3VBDl2c/?utm_source=ig_embed&amp;utm_medium=loading" target="_blank">
                A post shared by CNN (@cnn)
            </a> on <time datetime="2018-11-18T01:00:10+00:00">Nov 17, 2018 at 5:00pm PST</time>
        </p>
    </div>
</blockquote>

->

{
    "type": "reference",
    "referent": {
        "id": "https://www.instagram.com/p/BqTW3VBDl2c/?utm_source=ig_embed&amp;utm_medium=loading",
        "type": "instagram",
        "provider": "https://api.instagram.com/oembed?url=",
        "service": "oembed"
    },
    "additional_properties": {
        "class": "instagram-media"
    }
}
class html2ans.parsers.embeds.VineEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

Vine embed parser.

Example:

<iframe class="vine-embed" src="https://vine.co/v/imPIVvJ6E5j/embed/simple"></iframe>

->

{
    "type": "reference",
    "referent": {
        "id": "imPIVvJ6E5j",
        "type": "vine",
        "provider": "https://vine.co/oembed.json?url=",
        "service": "oembed"
    },
    "additional_properties": {
        "class": "vine-embed"
    }
}
class html2ans.parsers.embeds.ArcPlayerEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

class html2ans.parsers.embeds.FacebookPostEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

Facebook post embed parser.

Example:

<iframe src="https://www.facebook.com/plugins/post.php?href=https://www.facebook.com/zuck/posts/10102883338403521&width=500"></iframe>

->

{
    "type": "reference",
    "referent": {
        "id": "https://www.facebook.com/zuck/posts/10102883338403521&width=500",
        "type": "facebook-post",
        "provider": "https://www.facebook.com/plugins/post/oembed.json/?url=",
        "service": "oembed"
    }
}
class html2ans.parsers.embeds.FacebookVideoEmbedParser[source]

Bases: html2ans.parsers.embeds.FacebookPostEmbedParser

Facebook video embed parser.

Example:

<iframe src="https://www.facebook.com/plugins/video.php?href=https://www.facebook.com/chicagotribune/videos/351670322074116/&show_text=0&width=560"></iframe>

->

{
    "type": "reference",
    "referent": {
        "id": "https://www.facebook.com/chicagotribune/videos/351670322074116/&show_text=0&width=560",
        "type": "facebook-video",
        "provider": "https://www.facebook.com/plugins/video/oembed.json/?url=",
        "service": "oembed"
    }
}
class html2ans.parsers.embeds.YoutubeEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

Youtube video embed parser.

Example:

<iframe src="https://www.youtube.com/embed/4I86iz4X4jM"></iframe>

->

{
    "type": "reference",
    "referent": {
        "id": "https://www.youtube.com/embed/4I86iz4X4jM",
        "type": "youtube",
        "provider": "https://www.youtube.com/oembed?format=json&url=",
        "service": "oembed"
    }
}
parse(element, *args, **kwargs)[source]

Parses the given element.

Parameters

element (bs4.element.Tag or bs4.element.Comment or bs4.element.NavigableString) – the element to parse

class html2ans.parsers.embeds.VimeoEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

Vimeo video embed parser.

Example:

<iframe src="https://player.vimeo.com/video/76979871"></iframe>

->

{
    "type": "reference",
    "referent": {
        "id": "https://player.vimeo.com/video/76979871",
        "type": "vimeo",
        "provider": "https://vimeo.com/api/oembed.json?url=",
        "service": "oembed"
    }
}
class html2ans.parsers.embeds.TumblrEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

Vimeo video embed parser.

Example:

<div class="tumblr-post" data-href="https://embed.tumblr.com/embed/post/67gzjB87rG0-5qSuAaoBxA/180352280783" data-did="a57f8b609347877835580bb80b3d7d8566419e40">'
    <a href="https://herepet.tumblr.com/post/180352280783/source-instagramcom-mydogiscutest-i-pwomise-i">
        https://herepet.tumblr.com/post/180352280783/source-instagramcom-mydogiscutest-i-pwomise-i
    </a>
</div>

->

{
    "type": "reference",
    "referent": {
        "id": "https://herepet.tumblr.com/post/180352280783/source-instagramcom-mydogiscutest-i-pwomise-i",
        "type": "tumblr",
        "provider": "https://www.tumblr.com/oembed/1.0?url=",
        "service": "oembed"
    }
}
class html2ans.parsers.embeds.SpotifyEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

Spotify embed parser.

Example:

<iframe src="https://open.spotify.com/user/112389858/playlist/4E55G0GYK0CuUWZ0IQiaoD"></iframe>

->

{
    "type": "reference",
    "referent": {
        "id": "https://open.spotify.com/user/112389858/playlist/4E55G0GYK0CuUWZ0IQiaoD",
        "type": "spotify",
        "provider": "https://embed.spotify.com/oembed/?url=",
        "service": "oembed"
    }
}
class html2ans.parsers.embeds.ImgurEmbedParser[source]

Bases: html2ans.parsers.embeds.AbstractEmbedParser

Imgur embed parser.

Example:

<blockquote class="imgur-embed-pub" lang="en" data-id="w7zCp">
    <a href="https://imgur.com/w7zCp">View post on imgur.com</a>
</blockquote>

->

{
    "type": "reference",
    "referent": {
        "id": "https://imgur.com/w7zCp",
        "type": "imgur",
        "provider": "https://api.imgur.com/oembed/?url=",
        "service": "oembed"
    }
}
class html2ans.parsers.embeds.IFrameParser[source]

Bases: html2ans.parsers.raw_html.RawHtmlParser

Iframe parser.

Example:

<iframe src="http://www.test.com?var=value" height="315" scrolling="no"></iframe>

->

{
    "type": "raw_html",
    "content": "<iframe src="http://www.test.com?var=value" height="315" scrolling="no"></iframe>",
    "additional_properties": {
        "height": 315
    }
}
is_applicable(element, *args, **kwargs)[source]

Checks applicability using applicable_elements and, optionally, applicable_classes

Parameters

element (bs4.element.Tag or bs4.element.Comment or bs4.element.NavigableString) – the element to parse

parse(element, *args, **kwargs)[source]

Parses the given element.

Parameters

element (bs4.element.Tag or bs4.element.Comment or bs4.element.NavigableString) – the element to parse