Giter Site home page Giter Site logo

mydrone / ipython-beautifulsoup Goto Github PK

View Code? Open in Web Editor NEW

This project forked from psycojoker/ipython-beautifulsoup

0.0 2.0 0.0 680 KB

Pretty HTML/XML rendering with syntax highlighting for BeautifulSoup objects in IPython notebook and qtconsole.

Python 3.22% Jupyter Notebook 96.41% HTML 0.37%

ipython-beautifulsoup's Introduction

IPython-BeautifulSoup

https://travis-ci.org/Psycojoker/ipython-beautifulsoup.svg?branch=master

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.

teaser

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

.find_all:

.find_all

Contributors

In chronological order:

Don't hesitate to add yourself.

ipython-beautifulsoup's People

Contributors

psycojoker avatar westurner avatar astalaseven avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.