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.

Use cases

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.2.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

activesoup-0.2.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: activesoup-0.2.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for activesoup-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7be05241ad13b1b6557c9cad3a0297c7a0559ce157d9e2d01acc637fbfe1748c
MD5 0a6753bbe7c53652a35389a02776be02
BLAKE2b-256 63c95c0be98955245abeb61e7beacc3c8afef2003587fb45295cb2f1d7459227

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: activesoup-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for activesoup-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 761478eeffd56fc8f52f7b1d3eb6bcf6a91291836def1b8247858f7cf845fec3
MD5 0d7b247f6fdcae5c5f23c621faf0ab36
BLAKE2b-256 48fdcc12f080947bc3954bc8bf157d0a101aa1a5850d07bbb4a99e6fe1092895

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