如何通过Python访问Javascript对象属性?

2024-06-25 23:10:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从Instagram图片的链接中提取特定信息,例如海报ID、图片上的喜好等

所有这些信息都在HTML中。 https://www.instagram.com/p/B4czZl5HJXv/

但是,我不知道如何使用Python

<script type="application/ld+json">
                {"@context":"http:\/\/schema.org","@type":"ImageObject","caption":"Traveling girl \ud83d\udcf8\u2728","representativeOfPage":"http:\/\/schema.org\/True","uploadDate":"2019-11-04T16:22:11","author":{"@type":"Person","alternateName":"@luizclas","mainEntityofPage":{"@type":"ProfilePage","@id":"https:\/\/www.instagram.com\/luizclas\/"}},"comment":[{"@type":"Comment","text":"Fiat500\ud83d\udda4","author":{"@type":"Person","alternateName":"@venerdi__17","mainEntityofPage":{"@type":"ProfilePage","@id":"https:\/\/www.instagram.com\/venerdi__17\/"}}},{"@type":"Comment","text":"Fabulous\ud83d\udcf8","author":{"@type":"Person","alternateName":"@photography_ps99","mainEntityofPage":{"@type":"ProfilePage","@id":"https:\/\/www.instagram.com\/photography_ps99\/"}}}],"commentCount":"107","contentLocation":{"@type":"Place","name":"S\u00e3o Paulo, Brazil","mainEntityofPage":{"@type":"CollectionPage","@id":"https:\/\/www.instagram.com\/explore\/locations\/112047398814697\/sao-paulo-brazil\/"},"address":{"@type":"PostalAddress","addressLocality":"S\u00e3o Paulo, Brazil","addressCountry":{"@type":"Country","name":"BR"}}},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":"17076"},"mainEntityofPage":{"@type":"ItemPage","@id":"https:\/\/www.instagram.com\/p\/B4czZl5HJXv\/"},"description":"17k Likes, 107 Comments - Luiz Claudio (@luizclas) on Instagram: \u201cTraveling girl \ud83d\udcf8\u2728\u201d","name":"Luiz Claudio on Instagram: \u201cTraveling girl \ud83d\udcf8\u2728\u201d"}
            </script>

例如,如何访问“alternativename”属性? 如何直接访问此数组和对象


Tags: httpscomidwwwtypeinstagramauthorperson