2016-07-30 5 views
6

私はたAccept-Languageヘッダを設定することができるよ、何とか私は「キープアライブ」にConnectionヘッダを設定できませんよ:Accept-languageヘッダーは設定できますが、Connectionヘッダーは設定できませんか? PhantomJS(パイソンとセレンwebdriverを)

from selenium import webdriver 
from selenium.webdriver.common.desired_capabilities import  DesiredCapabilities 

webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.Accept-Language'] = 'ru-RU' 

webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.Connection'] = "keep-alive" 

driver = webdriver.PhantomJS("/home/user/bin/phantomjs",service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any']) 

driver.set_window_size(1120, 550) 

driver.get("http://www.httpbin.org/headers") 

print(driver.page_source) 

出力

<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">{ 
    "headers": { 
    "Accept":  "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 
    "Accept-Encoding": "gzip, deflate", 
    "Accept-Language": "ru-RU", 
    "Host": "www.httpbin.org", 
    "User-Agent": "Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1" 
    } 
} 
</pre></body></html> 

ので、私はそれらのヘッダの例を見ないと正確にそのままそれらを使用し、ないサイコロ、Iはヘッダ自体、何らかの理由で、多分考えまたはフィールドは大文字と小文字を区別しました。接続ヘッダーまたはキープアライブヘッダーを設定するにはどうすればよいですか?

答えて

2

phantomjs接続のデフォルトヘッダーのように見えますが、Keep-aliveの場合、PhantomJSを使用していないときでも、ヘッダーを表示するサイトはConnectionヘッダーを表示しません。 Fiddlerを使用してリクエストを見ると、接続キープアライブヘッダーがあることがわかります。

GET /ヘッダーHTTP/1.1承認:text/html、application/xhtml + xml、application/xml; q = 0.9 、/; Q = 0.8
のUser-Agent:Mozillaの/ 5.0(Windows NTの6.1; WOW64)のAppleWebKit/538.1(KHTML、ヤモリなど)PhantomJS/2.1.1サファリ/ 538.1

接続:キープAlive

Accept-Encoding:gzip、deflate Accept-Language:en-US、* ホスト:www.httpbin.org

関連する問題