Skip to main content

Infers an image to use for a given URL

Project description

Infer an image for a given URL

What this does:

Given the URL of a website (e.g. "https://www.mozilla.org"), it attempts to find the most appropriate image that represents this site, and returns the URL of that image.

How it works:

The HTML of the page is parsed (BeautifulSoup) and meta/link tags are extracted which may contain clues as to which image to use. Failing this, the favicon is tried, or else it searches for the first img tag following the first h1 on the page.

The default search order is:

DEFAULT_CHECK_ORDER = [
    SCHEMA_IMAGE,
    OG_IMAGE,
    TWITTER_IMAGE,
    MS_WIDE_310,
    MS_SQUARE_310,
    ICON,
    APPLE_TOUCH_ICON,
    MS_SQUARE_150,
    MS_SQUARE_70,
    FAV_ICON,
    FIRST_IMAGE,
]

Which corresponds to:

  • meta tag with itemprop="image" or property="image"
  • meta tag with property="og:image:secure_url" or property="og:image"
  • meta tag with name="twitter:image"
  • meta tag with name="msapplication-wide310x150logo"
  • meta tag with name="msapplication-square310x310logo"
  • link tag with rel="apple-touch-icon" (if 'sizes' is provided, the link tag with the largest minimum dimension is selected)
  • link tag with rel="icon" (if 'sizes' is provided, the link tag with the largest minimum dimension is selected)
  • meta tag with name="msapplication-square150x150logo"
  • meta tag with name="msapplication-square70x70logo"
  • requesting "{scheme}://{domain}/favicon.ico" to see if it exists
  • the first img tag siblings with an h1 tag.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

urlimage-0.0.2.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file urlimage-0.0.2.tar.gz.

File metadata

  • Download URL: urlimage-0.0.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for urlimage-0.0.2.tar.gz
Algorithm Hash digest
SHA256 1647eb4f5519dee562c03080fa2048eddd8d7f55f25c3bb8822d330e750dcdb1
MD5 72389510a9b0166bdc20f5df88d17e41
BLAKE2b-256 84c958f8154f8b634813d5bde6377165c53a7dc04646d829491d746d7d18bded

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page