Ctrl + K
DocumentationLog inGet started

tessl/pypi-w3lib

tessl install tessl/pypi-w3lib@2.3.0

Library of web-related functions for HTML manipulation, HTTP processing, URL handling, and encoding detection

Agent Success

Agent success rate when using this tile

84%

Improvement

Agent success rate improvement when using this tile compared to baseline

0.91x

Baseline

Agent success rate without this tile

92%

task.mdevals/scenario-8/

URL Parameter Manager

Build a URL parameter manager that updates multiple query parameters in URLs to prepare them for API requests or web scraping tasks.

Capabilities

Update tracking parameters in URLs

  • Given the URL http://example.com/page?id=123&source=email, updating with parameters {'utm_source': 'newsletter', 'utm_campaign': 'winter2024'} returns http://example.com/page?id=123&source=email&utm_source=newsletter&utm_campaign=winter2024 @test
  • Given the URL http://shop.com/product?item=456, updating with parameters {'ref': 'partner', 'discount': '10'} returns http://shop.com/product?item=456&ref=partner&discount=10 @test

Replace existing parameters in URLs

  • Given the URL http://api.example.com/data?format=json&limit=100, updating with parameters {'format': 'xml', 'limit': '50'} returns http://api.example.com/data?format=xml&limit=50 @test
  • Given the URL http://example.com/search?q=old&page=1, updating with parameters {'q': 'new search term', 'page': '5'} returns http://example.com/search?q=new+search+term&page=5 @test

Mix adding and replacing parameters

  • Given the URL http://example.com/search?q=python&category=tutorials, updating with parameters {'q': 'web-scraping', 'sort': 'date', 'limit': '20'} returns http://example.com/search?q=web-scraping&category=tutorials&sort=date&limit=20 @test

Handle URLs without query parameters

  • Given the URL http://example.com/page, updating with parameters {'session': 'abc123', 'user': 'guest'} returns http://example.com/page?session=abc123&user=guest @test

Implementation

@generates

API

def update_url_parameters(url: str, parameters: dict[str, str]) -> str:
    """
    Update multiple query parameters in a URL, adding new ones or replacing existing ones.

    Args:
        url: The URL to modify
        parameters: Dictionary of parameter names and values to add or replace

    Returns:
        str: The modified URL with updated parameters
    """

Dependencies { .dependencies }

w3lib { .dependency }

Web utility library providing URL manipulation functions.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/w3lib@2.3.x
tile.json