selenium+Firefox更改ua请求头

  • Post author:
  • Post category:其他


火狐内核更改ua和Chrome并不一样,很多教程用的是Options来更改,但对火狐不会报错也不会生效,正确的方法是用Profile来更改,直接上代码

import time

from selenium import webdriver

url = 'http://www.sunchateau.com/free/UA.htm'

pro = webdriver.FirefoxProfile()

ua = 'are you ok'

pro.set_preference('general.useragent.override', ua)

driver = webdriver.Firefox(firefox_profile=pro)
driver.get(url)

time.sleep(10)
driver.close()

会报warning,但是不影响使用



版权声明:本文为qq_40065962原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。