2013-07-17 27 views
1

我是Python新手,但我想我在3小時的研究後處理問題不算太壞。 由於cookie的原因,我的POST請求繞過了登錄牆,但它從不在網頁上發佈我想要的信息。 :(使用cookie設置Python的發佈請求,但仍不能正確發送數據

這裏是我的代碼:

import requests 

url = "url" 
headers = { 
'Cookie': 'cookie', 
'Content-Type': 'multipart/form-data', 
'Accept': 'text/html,application/xhtml+xml', 
'Accept-Language': 'en-gb,en;q=0.5', 
'Accept-Encoding': 'gzip,deflate', 
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 
'Keep-Alive': '300', 
'Connection': 'keep-alive', 
'Content-Length': '41' 
} 

payload = { 
'seo_page[keyword]': 'test', 
'commit': 'Save' 
} 

p = requests.post(url, data=payload, headers=headers) 

print p.text.encode('utf8') 
print p.encoding 
print p.headers 

這是,我認爲,正是在15個主題真實勸我讀過有關如何發佈Web窗體頁DATAS

打印頁。 text.encode(「utf-8」)給我的HTML沒有我試圖發送DATAS。

任何想法?:)

非常感謝您!

回答

0

一切都好! POST請求被正確設置,但由於邊緣情況,它仍然不接受數據: 我嘗試POST的網站是在Ruby on Rails上開發的,它要求提供額外的驗證令牌(爲了避免CSRF攻擊而開發)。

乾杯!

相關問題