我對(duì)編碼仍然很陌生(已經(jīng)編碼了一周),所以我在使用一個(gè)非?;镜墓δ芊矫婵嗫鄴暝?。我正在嘗試使用python登錄網(wǎng)站,但是我很難更改set-cookie標(biāo)頭。請(qǐng)參閱下面的當(dāng)前代碼:import requeststargetURL = "http://hostip/v2_Website/aspx/login.aspx"headers = {"Host": "*host IP*","User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0"}response = requests.get(url=targetURL, proxies=proxies, headers=headers,)response_headers = response.headers當(dāng)我打印response.headers時(shí),我得到以下信息:{'Cache-Control': 'no-cache, no-store', 'Pragma': 'no-cache,no-cache', 'Content-Length': '15671', 'Content-Type': 'text/html; charset=utf-8', 'Expires': '-1', 'Server': 'Microsoft-IIS/7.5', 'X-AspNet-Version': '2.0.50727', 'Set-Cookie': 'ASP.NET_SessionId=vq5q4lzlrqiiebbmxw341yic; path=/; HttpOnly, CookieLoginAttempts=5; expires=Tue, 14-Aug-2018 17:14:09 GMT; path=/', 'X-Powered-By': 'ASP.NET', 'Date': 'Tue, 14 Aug 2018 07:14:10 GMT', 'Connection': 'close'}顯然,當(dāng)我在HTTP POST中使用這些標(biāo)頭時(shí),由于POST具有Set-Cookie標(biāo)頭而不是Cookie值,所以它失敗。我的目標(biāo)如下:將Set-Cookie鍵更新/更改為Cookie然后,我想刪除Cookie鍵中不需要的值添加其他鍵和值最終,我想將標(biāo)頭更改為以下標(biāo)題,以便可以將其用于POST,以便我傳遞登錄憑據(jù):POST /Test server/aspx/Login.aspx?function=Welcome HTTP/1.1Host: *Host IP*User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: http://*HostIP*/v2_Website/aspx/main.aspx?function=WelcomeCookie: ASP.NET_SessionId=3vy0fy55xsmffhbotikrwh55; CookieLoginAttempts=5; Admin=falseConnection: closeUpgrade-Insecure-Requests: 1Content-Type: application/x-www-form-urlencodedContent-Length: 220我的上述目標(biāo)甚至可能嗎?如果是這樣的話,我什至看不到修改字典的過(guò)程,如何實(shí)現(xiàn)呢?再次提醒您,我在編碼領(lǐng)域仍然非常環(huán)保,并試圖“像編碼員一樣思考”,因此,將響應(yīng)的技術(shù)水平降低一點(diǎn)是非常值得的,這樣我就可以理解您的響應(yīng)和建議。任何幫助將是巨大的!
用Python編輯字典
慕碼人8056858
2021-05-07 18:08:01