Selenium PhantomJS custom headers in Python

前端 未结 4 1383
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 18:35

I want to add \"custom headers\" to Selenium PhantomJS in python. These are the headers I wanna add.

headers = { \'Accept\':\'*/*\',
            \'Accept-Encodi         


        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 19:24

    from selenium import webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    
    dcap = dict(DesiredCapabilities.PHANTOMJS)
    dcap["phantomjs.page.settings.userAgent"] = (
    "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
    "(KHTML, like Gecko) Chrome/15.0.87")
    
    driver = webdriver.PhantomJS(desired_capabilities=dcap)
    driver.get("http://www.google.com")
    

提交回复
热议问题