setting request headers in selenium

后端 未结 9 1200
青春惊慌失措
青春惊慌失措 2020-11-29 21:53

I\'m attempting to set the request header \'Referer\' to spoof a request coming from another site. We need the ability test that a specific referrer is used, which returns a

9条回答
  •  甜味超标
    2020-11-29 22:40

    For those people using Python, you may consider using Selenium Wire, which can set request headers, as well as provide you with the ability to inspect requests and responses.

    from seleniumwire import webdriver  # Import from seleniumwire
    
    # Create a new instance of the Firefox driver
    driver = webdriver.Firefox()
    
    # Set the request header using the `header_overrides` attribute
    driver.header_overrides = {
        'Referer': 'referer_string',
    }
    
    # All subsequent requests will now contain the Referer
    driver.get('https://mysite')
    

提交回复
热议问题