This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Custom rendering of beautifulsoup objects in IPython notebook and qtconsole

Project Description

IPython-BeautifulSoup

IPython-BeautifulSoup is an IPython extension for displaying BeautifulSoup HTML/XML objects as prettified and syntax highlighted HTML blocks in IPython notebook and qtconsole.

Syntax highlighting is accomplished with Pygments.

Install

Simply run:

pip install "ipython-beautifulsoup[bs4]"

Installing IPython Notebook

See the IPython installation docs for details.

To install IPython notebook or qtconsole as well, append notebook and/or qtconsole to the extras specifier after “bs4” separated by a “,”, like this:

pip install "ipython-beautifulsoup[bs4,notebook,qtconsole]"

On Ubuntu LTS, if you want to install IPython notebook, you’ll need to do this before:

sudo apt-get install python-dev g++

(use python3-dev if you’re using Python 3)

For the qtconsole do this (if you do this in a virtualenv) (WARNING: it’s slow):

sudo apt-get install make cmake qt4-qmake libqt4-dev
pip install pyside

Usage

In IPython notebook or qtconsole, run:

%load_ext soup

This will push a series of callables into your current context, as well as a monkey-patched BeautifulSoup and requests.

You can now use BeautifulSoup like you would if it was imported from the corresponding module.

There is great chances that you’ll want to configure the output by using configure_ipython_beautifulsoup, for example like this (just after the %load_ext):

configure_ipython_beautifulsoup(show_html=True, show_css=True, show_js=False)

To see configure_ipython_beautifulsoup documentation just do (in any interface of IPython):

configure_ipython_beautifulsoup?

This also loads a shortcut function called p (for Parse) defined as follows:

def p(url):
    if requests is not None:
        return BeautifulSoup(requests.get(url).contents)
    return BeautifulSoup(urlopen(url).read())

A note on security

WARNING

By nature of including external HTML, JS, and CSS, this extension is inherently unsafe if you choose to render the html by setting show_html to True when calling “configure_ipython_beautifulsoup“.

By default, <script>, <link>, and <style> tags are removed but this isn’t a 100% guarantee that this is secure if you choose to render the html, use at your own risk.

The safest option is to set all options of configure_ipython_beautifulsoup to False (the default).

Screenshots

IPython Notebook

.find:

.find_all:

Contributors

In chronological order:

Don’t hesitate to add yourself.

Changelog

0.3 (2014-08-26)

0.2 (2014-01-06)

0.1.1 (2014-01-04)

  • bug fixes

0.1 (2014-01-04)

  • Init
Release History

Release History

This version
History Node

0.3

History Node

0.2

History Node

0.1.1

History Node

0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
ipython_beautifulsoup-0.3-py2.7.egg (4.6 kB) Copy SHA256 Checksum SHA256 2.7 Egg Aug 26, 2014
ipython_beautifulsoup-0.3-py2.py3-none-any.whl (7.4 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Aug 26, 2014
ipython-beautifulsoup-0.3.tar.gz (4.9 kB) Copy SHA256 Checksum SHA256 Source Aug 26, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting