Skip to main content

Extract the title, image and description from any URL.

Project description

Current release: v0.2 - see CHANGES.txt for details.

Simple usage

Working with the summary package:

>>> import summary
>>> s = summary.Summary('')
>>> s.extract()
>>> s.title
>>> s.image
>>> s.description
u'summary - Summary is a complete solution to extract the title, image and description from any URL.'

Batch usage with HTML rendering

If you fork or clone the repo you can use like this:

>>> import summary
>>> summary.GET_ALL_DATA = True # default is False
>>> urls = [
>>> from summarize import summarize, render
>>> summaries, result, speed = summarize(urls)
[BadImage] RatioImageException(398, 82):
[BadImage] AdblockURLFilter:
[BadImage] AdblockURLFilter:
[BadImage] AdblockURLFilter:
[BadImage] AdblockURLFilter:
[BadImage] AdblockURLFilter:
[BadImage] RatioImageException(379, 64):
[BadImage] TinyImageException(16, 16):
[BadImage] TinyImageException(16, 16):>
Success: 3.
>>> html = render(template="news.html",
    summaries=summaries, result=result, speed=speed)
>>> with open('demo.html', 'w') as file:
...   file.write(html)

In a nutshell

Summary requests the page from the URL, then uses extraction to parse the HTML.

Worth mentioning that it downloads the head tag first, performs specific extraction techniques, and goes further to body only if extracted data is not complete. Unless summary.GET_ALL_DATA = True.

The resulting lists of titles, images, and descriptions are filtered on the fly to rule out unwanted items like ads, tiny images (tracking images or sharing buttons), and plain white images. See the whole list of filters below.

Many thanks to Will Larson (@lethain) for adapting his extraction library to version 0.2 to accomodate summary.


The purpose of the HTML rendering mechanism is just to visualize extracted data. The included Jinja2 template (news.html) is built on top of bootstrap and displays the summaries in a nice responsive grid layout.

You can completely disregard the rendering mechanism and just import summary module for data extraction and filtering. You probably have your own means to render the data, so you only need the summary folder.


![news.html preview](

This is the output having summary.GET_ALL_DATA = True.

Clicking the summary title, image and description cycles through the multiple extracted values.


And this one produced much faster (see footer) with summary.GET_ALL_DATA = False. It contains only the first valid item of each kind - title, image, and description. This is the default behaviour.



Pip it for simple usage:

$ pip install summary-extraction

Or clone the repo if you need rendering:

$ virtualenv env
$ source env/bin/activate
$ git clone
$ pip install -r summary/requirements.txt

$ cd summary
$ python # see the usage instructions above


Base required packages are extraction and requests, but it doesn’t do much withouth adblockparser and Pillow:

Jinja2==2.7.2 # only for rendering
re2==0.2.20 # good for adblockparser


Filters are callable classes that perform specific data checks.

For the moment there are only image filters. The image URL is passed as input parameter to the first filter. The check is performed and the URL is returned if it is valid, so it is passed to the second filter and so on. When the check fails it returns None.

This pattern makes it possible to write the filtering routine like this:

def _filter_image(self, url):
  "The param is the image URL, which is returned if it passes *all* the filters."
  return reduce(lambda f, g: f and g(f),

images = filter(None, map(self._filter_image, image_urls))
  • AdblockURLFilter

    Uses adblockparser and returns None if it should_block the URL.

    Hats off to Mikhail Korobov (@kmike) for the awesome work. It gives a lot of value to this mashup repo.

  • NoImageFilter

    Retrieves actual image file, and returns None if it fails.

    Otherwise it returns an instance of the filters.Image class containing the URL, together with the size and format of the actual image. Basically it hydrates this instance which is passed to following filters. The Image.__repr__ override returns just the URL so we can write the beautiful filtering routine you can see above.

    Worth mentioning again that it only gets first few chunks of the image file until the PIL parser gets the size and format of the image.

  • SizeImageFilter

    Checks the filters.Image instance to have proper size.

    This can raise following exceptions based on defined limits: TinyImageException, HugeImageException, or RatioImageException. If any of these happens it returns None.

  • MonoImageFilter

    Checks whether the image is plain white and returns None.

    This filter retrieves the whole image file so it has an extra regex check before. E.g.: rules out these URLs:

  • FormatImageFilter

    Rules out animated gif images for the moment. This can be extended to exclude other image formats based on file contents.

That’s it for now. You’re very welcome to contribute.

Comments and suggestions are welcome as well. Cheers, @ducu

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

summary-extraction-0.2.tar.gz (16.4 kB view hashes)

Uploaded Source

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