Overview
Robox is a simple library with a clean interface for exploring/scraping the web or testing a website you’re developing. Robox can fetch a page, click on links and buttons, and fill out and submit forms. Robox is built on top of two excelent libraries: httpx and beautifulsoup4.
Robox has all the standard features of httpx, including async, plus:
- clean api
- caching
- downloading files
- history
- retry
- parsing tables
- understands robots.txt
Examples
from robox import Robox
with Robox() as robox:
page = robox.open("https://httpbin.org/forms/post")
form = page.get_form()
form.fill_in("custname", value="foo")
form.check("topping", values=["Onion"])
form.choose("size", option="Medium")
form.fill_in("comments", value="all good in the hood")
form.fill_in("delivery", value="13:37")
page = page.submit_form(form)
assert page.url == "https://httpbin.org/post"
or use async version:
import asyncio
from pprint import pprint
from robox import AsyncRobox
async def main():
async with AsyncRobox(follow_redirects=True) as robox:
page = await robox.open("https://www.google.com")
form = page.get_form()
form.fill_in("q", value="python")
consent_page = await page.submit_form(form)
form = consent_page.get_form()
page = await consent_page.submit_form(form)
links = page.get_links()
pprint([link for link in links if "Python" in link.text])
asyncio.run(main())
Caching can be easily configured via httpx-cache
from robox import Robox, DictCache, FileCache
with Robox(options=Options(cache=DictCache())) as robox:
p1 = robox.open("https://httpbin.org/get")
assert not p1.from_cache
p2 = robox.open("https://httpbin.org/get")
assert p2.from_cache
Failed requests that are potentially caused by temporary problems such as a connection timeout or HTTP 500 error can be retried:
with Robox(
options=Options(
retry=True,
retry_max_attempts=2,
raise_on_4xx_5xx=True,
)
) as robox:
page = robox.open("https://httpbin.org/status/503,200")
assert page.status_code == 200
Parse tables with rowspan and colspan:
with Robox() as robox:
page = robox.open("https://html.com/tables/rowspan-colspan/")
tables = page.get_tables()
for table in tables:
pprint(table.get_rows())
[['65', '65', '40', '40', '20', '20'],
['Men', 'Women', 'Men', 'Women', 'Men', 'Women'],
['82', '85', '78', '82', '77', '81']]
...
An example on how to reuse authentication state with cookies:
with Robox() as robox:
page = robox.open("https://news.ycombinator.com/login")
form = page.get_forms()[0]
form.fill_in("acct", value=os.getenv("PASSWORD"))
form.fill_in("pw", value=os.getenv("USERNAME"))
page.submit_form(form)
robox.save_cookies("cookies.json")
with Robox() as robox:
robox.load_cookies("cookies.json")
page = robox.open("https://news.ycombinator.com/")
assert page.parsed.find("a", attrs={"id": "logout"})
See examples folder for more detailed examples.
Installation
Using pip:
pip install robox
Robox requires Python 3.8+. See Changelog for changes.
Metadata
Release files for robox 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| robox-0.2.3.tar.gz | 16.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| robox-0.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.4 kB
Release files / robox-0.2.3.tar.gz
| Download URL | robox-0.2.3.tar.gz |
|---|---|
| Size | 16.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c7452e74153b9c15a48ec62fc2e9d4fc7b97229c18aae706f75243c17253378c
|
|
BLAKE2b-256 checksum How to use checksums |
be9dfacced0c25c43720d1975321e6a6f9e3c6991380693269dbea593177c3d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
|
Release files / robox-0.2.3-py3-none-any.whl
| Download URL | robox-0.2.3-py3-none-any.whl |
|---|---|
| Size | 18.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0dc31ab1a4a8fda069521cabc4fdef1925279dfeca9129f2910f8a334d9b618
|
|
BLAKE2b-256 checksum How to use checksums |
22dee48dfb63a58d0d452c37e788cd472fe07b50c4e13e801fd1a78b7773cb29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
|
Security for robox 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.