前言
selenium的webdriver本身沒(méi)有api能做這個(gè)事情,詳見(jiàn)issue。
國(guó)內(nèi)的博客全抄來(lái)抄去,說(shuō)selenium直接加add_argument參數(shù)就好了,弄得找了好幾天找代碼問(wèn)題,上外網(wǎng)查秒解決。所以要學(xué)好計(jì)算機(jī)還是得英文吶~~文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-510996.html
解決
- 安裝seleniumwire庫(kù)
pip3 install selenium-wire
- 上代碼完事
from seleniumwire import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument("no-sandbox")
chrome_options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.header_overrides = {"tmp": "tomjobs"}
driver.get("https://httpbin.org/headers") # 可以看到請(qǐng)求的header頭
print(driver.page_source)
參考:https://stackoverflow.com/questions/15645093/setting-request-headers-in-selenium文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-510996.html
到了這里,關(guān)于selenium請(qǐng)求chrome如何添加header頭的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!