編輯:我已經重申了這個問題,因爲我不僅可以不登錄,但我甚至不能發出沒有錯誤的簡單POST請求。看下面的代碼,它應該返回一個json列表,而不是我得到一個錯誤頁面。無法發出POST請求
import urllib2 import cookielib import calendar import datetime opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel = 0), urllib2.HTTPSHandler(debuglevel = 0), urllib2.HTTPCookieProcessor(cookielib.CookieJar()), ) opener.addheaders = [ ('User-agent', "Mozilla/5.0"), ("Content-Type", "application/json") ] data = '{"searchFilter":{"TimeFrame":10000,"NotTradingExotics":false,"Page":0,"PageSize":20,"AffiliateId":-1,"SortExpression":"Ranking","SortDirection":"Ascending"}}'.encode() tmp = calendar.timegm(datetime.datetime.now().utctimetuple()) * 1000 url = "https://www.zulutrade.com/WebServices/Performance.asmx/SearchProviders?_tsmp=" + str(tmp) opener.open(url, data) res = opener.open(url, data) print opener.handlers[7].cookiejar._cookies if "An unexpected error occured" in res.read(): raise Exception("Login failed")
還是同樣的結果 – siamii
檢查你的cookies,你有沒有看看HTTPFox向你展示的任何對應信息? – elbuild