Skip to main content

Easier wrangling of web documents

Project description

Build Status Coverage Status

Soupy is a wrapper around BeautifulSoup that makes it easier to build complex queries when wrangling web data.

Here’s an example of a Soupy query.

from soupy import Soupy, Q

html = """
<div id="main">
  <div>The web is messy</div>
  and full of traps
  <div>but Soupy loves you</div>
</div>"""

print(Soupy(html).find(id='main').children
      .each(Q.text.strip()) # extract text from each node, trim whitespace
      .filter(len)          # remove empty strings
      .val())               # dump out of Soupy

# ['The web is messy', 'and full of traps', 'but Soupy loves you']

The same query using BeautifulSoup:

 from bs4 import BeautifulSoup, NavigableString

html = """
<div id="main">
  <div>The web is messy</div>
  and full of traps
  <div>but Soupy loves you</div>
</div>"""

result = []
for node in BeautifulSoup(html).find(id='main').children:
    if isinstance(node, NavigableString):
        text = node.strip()
    else:
        text = node.text.strip()
    if len(text):
        result.append(text)

print(result)

For more information, see the Soupy Documentation

Installation

pip install soupy

Dependencies

six and BeautifulSoup4

Soupy is supported on Python 2.6+ and 3.3+

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

soupy-0.2.tar.gz (8.3 kB view details)

Uploaded Source

File details

Details for the file soupy-0.2.tar.gz.

File metadata

  • Download URL: soupy-0.2.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for soupy-0.2.tar.gz
Algorithm Hash digest
SHA256 dd920ae4da885ee4ae11a28982adfc448b764f00fe0a6da6a369f399dff0fc95
MD5 86ee9c74ddf06e083906c2f7e1c84bc3
BLAKE2b-256 27de011e743271c3f8e78ad03dd31bb71e71a8da5fdf2ddf47872dacd52df3b6

See more details on using hashes here.

Provenance

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