Skip to content

Support a web browser-looking user agent in requests #101

Description

@johnthagen

Some websites and CDNs are increasingly disallowing connections from non-browser-looking entities. This results in some false positive from URL checking as 403 is returned to htmlproofer, but the link is valid if opened from a browser.

I've had success adding a user-agent in the past like this:

        req = urllib.request.Request(
            url,
            headers={
                # Mimic a web browser to bypass certain CDN 403 blocking.
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36"
            },
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions