请注意,我对编码世界还是很绿色的,只写了一个星期的代码。因此,如果我的问题很愚蠢,请原谅我。
我当前的目标是使用python脚本登录网站。
我需要从HTTP响应标头中提取信息并将其添加到我的POST中,这是我当前的脚本:
import requests
targetURL = "http://website.com/login.aspx"
headers = { "Host": "192.168.56.101",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0"}
get_request = requests.get(url=targetURL,
headers=headers)
我得到的答复如下:
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache,no-cache
Content-Length: 15748
Content-Type: text/html; charset=utf-8
Expires: -1
Set-Cookie: ASP.NET_SessionId=123456
一个人如何用从上面收到的信息创建一个HTTP帖子?
任何信息将不胜感激。
答案 0 :(得分:1)
requests.get
的返回值是一个具有可以访问的属性的对象。请尝试以下操作:
response = requests.get(url=targetURL, headers=headers)
response_headers = response.headers
response_headers
是字典。您可以对其进行修改并将其传递给您所需的任何内容。