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-10/

URL Query Parameter Manager

Build a URL parameter management utility that can update tracking and configuration parameters in URLs.

Background

You're building a web crawler that needs to add tracking identifiers and modify configuration parameters in URLs before making requests. The URLs come from various sources and may or may not already contain query parameters.

Requirements

Implement a function update_url_parameters that takes a URL and updates it with new parameter values:

  1. The function should accept:

    • A URL (string)
    • A session ID parameter to add/update
    • A language preference parameter to add/update
  2. The function should:

    • Add the session ID parameter (session_id) if it doesn't exist
    • Replace the session ID parameter if it already exists
    • Add the language parameter (lang) if it doesn't exist
    • Replace the language parameter if it already exists
    • Preserve all other existing query parameters
    • Maintain the URL structure (scheme, domain, path, fragment)
  3. Return the modified URL as a string

Implementation Files

Create your implementation in url_manager.py.

Dependencies { .dependencies }

w3lib { .dependency }

Provides web-related utility functions for URL manipulation.

Test Cases

  • Should add parameters to URL without query string @test

    • Input: URL "https://example.com/page" with session_id "abc123" and lang "en"
    • Expected: "https://example.com/page?session_id=abc123&lang=en"
  • Should replace existing parameters @test

    • Input: URL "https://example.com/search?q=test&session_id=old123&lang=fr" with session_id "new456" and lang "es"
    • Expected: "https://example.com/search?q=test&session_id=new456&lang=es"
  • Should handle mix of new and existing parameters @test

    • Input: URL "https://api.example.com/data?format=json&session_id=xyz" with session_id "updated789" and lang "de"
    • Expected: "https://api.example.com/data?format=json&session_id=updated789&lang=de"

Version

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