setting request headers in selenium

后端 未结 9 1201
青春惊慌失措
青春惊慌失措 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:48

    I had the same issue. I solved it downloading modify-headers firefox add-on and activate it with selenium.

    The code in python is the following

    fp = webdriver.FirefoxProfile()
    path_modify_header = 'C:/xxxxxxx/modify_headers-0.7.1.1-fx.xpi'
    fp.add_extension(path_modify_header)
    
    fp.set_preference("modifyheaders.headers.count", 1)
    fp.set_preference("modifyheaders.headers.action0", "Add")
    fp.set_preference("modifyheaders.headers.name0", "Name_of_header") # Set here the name of the header
    fp.set_preference("modifyheaders.headers.value0", "value_of_header") # Set here the value of the header
    fp.set_preference("modifyheaders.headers.enabled0", True)
    fp.set_preference("modifyheaders.config.active", True)
    fp.set_preference("modifyheaders.config.alwaysOn", True)
    
    driver = webdriver.Firefox(firefox_profile=fp)
    

提交回复
热议问题