Home > Blockchain >  How to Get Title and Brief Description from a URL in Python?
How to Get Title and Brief Description from a URL in Python?

Time:06-11

In Discord, if you post a link, Discord will find the title, and a brief summary of the linked webpage: enter image description here

How can I replicate this behavior in Python?

CodePudding user response:

Similar to this SO: https://stackoverflow.com/a/43154489/9964778

You need to get the value of some meta tags which starts with "og". In your example, you have in the source code below with the related metadata for title, description, image, among other fields

<meta property="og:site_name" content="livescience.com">
<meta property="og:image" content="https://cdn.mos.cms.futurecdn.net/W3wpBCQ4hEL4dthLYnsosK-1200-80.gif">
<meta property="og:image:width" content="1200">
<meta property="og:type" content="article">
<meta property="article:publisher" content="https://www.facebook.com/livescience?cmpid=556687">
<meta property="og:title" content="Alien shopping-bag ocean weirdo has glowing Cheetos for guts">
<meta property="og:url" content="https://www.livescience.com/alien-glowing-cheeto-sea-cucumber">
<meta property="og:description" content="The deep-sea creature surprised scientists.">
  • Related