Proxy Port logo
How-to Guides > How to set up a proxy for MechanicalSoup

How to set up a proxy for MechanicalSoup

To set up a proxy for MechanicalSoup, you can use the requests library which is used by MechanicalSoup for making HTTP requests. Here is an example code that sets up a proxy for MechanicalSoup using requests:

import mechanicalsoup
import requests

# Set up the proxy
proxy = {'http': 'http://proxy.example.com:8080',
         'https': 'http://proxy.example.com:8080'}

# Set up a requests session with the proxy
session = requests.Session()
session.proxies.update(proxy)

# Create a MechanicalSoup browser with the requests session
browser = mechanicalsoup.StatefulBrowser(session=session)

# Use the browser to make requests using the proxy
browser.open("http://example.com")

            
        
See also:
Proxy for scraping
More