Skip to main content

A pure-python headless browser

Project description

https://github.com/jelford/activesoup/workflows/Build/badge.svg https://img.shields.io/pypi/v/activesoup.svg?maxAge=3600

A simple library for interacting with the web from python

Description

activesoup combines familiar python web capabilities for convenient headless “browsing” functionality:

  • Modern HTTP support with requests - connection pooling, sessions, …

  • Convenient access to the web page with an interface inspired by beautifulsoup - convenient HTML navigation.

  • Robust HTML parsing with html5lib - parse the web like browsers do.

Full documentation can be found at https://activesoup.dev.

Use cases

activesoup aims to provide just enough functionality for basic web automation / crawler tasks. Consider using activesoup when:

  • You’ve already checked out the requests-html

  • You need to actively interact with some web-page from Python (e.g. submitting forms, downloading files)

  • You don’t control the site you need to interact with (if you do, just make an API).

  • You don’t need javascript support (you’ll need selenium or phantomjs).

Usage examples

Log into a website, and download a CSV file that’s access-protected:

>>> import activesoup

>>> # Start a session
>>> d = activesoup.Driver()

>>> page = d.get("https://httpbin.org/forms/post")

>>> # conveniently access elements, inspired by BeautifulSoup
>>> form = page.form

>>> # get the power of raw xpath search too
>>> form.find('.//input[@name="size"]')
BoundTag<input>
>>> # any element, searching by attribute
>>> form.find('.//*', name="size")
BoundTag<input>
>>> # or just search by attribute
>>> form.find(name="size")
BoundTag<input>

>>> # inspect element attributes
>>> print([i['name'] for i in form.find_all('input')])
['custname', 'custtel', 'custemail', 'size', 'size', 'size', 'topping', 'topping', 'topping', 'topping', 'delivery']

>>> # work actively with objects on the page
>>> r = form.submit({"custname": "john", "size": "small"})

>>> # responses parsed and ready based on content type
>>> r.keys()
dict_keys(['args', 'data', 'files', 'form', 'headers', 'json', 'origin', 'url'])
>>> r['form']
{'custname': 'john', 'size': 'small', 'topping': 'mushroom'}

>>> # access the underlying requests.Session too
>>> d.session
<requests.sessions.Session object at 0x7f283dc95700>

>>> # log in with cookie support
>>> d.get('https://httpbin.org/cookies/set/foo/bar')
>>> d.session.cookies['foo']
'bar'

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

activesoup-0.3.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

activesoup-0.3.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file activesoup-0.3.0.tar.gz.

File metadata

  • Download URL: activesoup-0.3.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for activesoup-0.3.0.tar.gz
Algorithm Hash digest
SHA256 18f25337a10e4f1985c51817b45d6335fa065bffea029fd1e1a60df51a083484
MD5 3f8112cf47d35582ed00113d997a77a7
BLAKE2b-256 592563b7a32b29d0729040c2d85b220a7b4e32dcd4dcc19d996184e603886bcc

See more details on using hashes here.

File details

Details for the file activesoup-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: activesoup-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for activesoup-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e64b9c184fa5965e3aa0234c63c1595e9b7f7e96821ccf73d9cfec9bfe90419
MD5 f468244bda907aaab356ec05b58447df
BLAKE2b-256 1a588234a159451decdb4c7eb523f61bd2879a0feb7da887788be5a4afa6b7f3

See more details on using hashes here.

Supported by

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