我正试图使用Python的post请求从一个网站上获取一些数据。
requests
图书馆。不幸的是,我无法发布网页链接,因为您必须登录网站才能使用它。
我尝试复制的请求的文件扩展名为.ehtml,这是我要重新创建的请求负载的一部分:
------WebKitFormBoundary8rntuVzldIBHkILv
Content-Disposition: form-data; name="session_id"
W0pNKn8AAQEAACD-XkYAAAAJ
------WebKitFormBoundary8rntuVzldIBHkILv
Content-Disposition: form-data; name="p_session_id"
W0pMOH8AAQEAABZSUVkAAAAD
------WebKitFormBoundary8rntuVzldIBHkILv
Content-Disposition: form-data; name="attach_key"
------WebKitFormBoundary8rntuVzldIBHkILv
Content-Disposition: form-data; name="chosen"
0
------WebKitFormBoundary8rntuVzldIBHkILv
Content-Disposition: form-data; name="debug"
------WebKitFormBoundary8rntuVzldIBHkILv
Content-Disposition: form-data; name="language"
en
------WebKitFormBoundary8rntuVzldIBHkILv
Content-Disposition: form-data; name="game_system_id"
NULL
------WebKitFormBoundary8rntuVzldIBHkILv
Content-Disposition: form-data; name="collection_detail_id"
NULL
------WebKitFormBoundary8rntuVzldIBHkILv
Content-Disposition: form-data; name="competition_id"
NULL
通过使用StackOverflow的一些问题提供的一些帮助,我目前已经成功地重新创建了它:
--30b11983bde849109a3dc93e139e16d4
Content-Disposition: form-data; name="session_id"
--30b11983bde849109a3dc93e139e16d4
Content-Disposition: form-data; name="p_session_id"
--30b11983bde849109a3dc93e139e16d4
Content-Disposition: form-data; name="attach_key"
--30b11983bde849109a3dc93e139e16d4
Content-Disposition: form-data; name="chosen"
0
--30b11983bde849109a3dc93e139e16d4
Content-Disposition: form-data; name="debug"
--30b11983bde849109a3dc93e139e16d4
Content-Disposition: form-data; name="language"
en
--30b11983bde849109a3dc93e139e16d4
Content-Disposition: form-data; name="game_system_id"
NULL
--30b11983bde849109a3dc93e139e16d4
Content-Disposition: form-data; name="collection_detail_id"
NULL
--30b11983bde849109a3dc93e139e16d4
Content-Disposition: form-data; name="competition_id"
NULL
这是使用以下代码完成的:
Q = {
"session_id" : (None,""),
"p_session_id" : (None,""),
"attach_key" : (None,""),
"chosen" : (None,"0"),
"debug" : (None,""),
"language" : (None,"en"),
"game_system_id" : (None,"NULL"),
"collection_detail_id" : (None,"NULL"),
"competition_id" : (None,"NULL")
}
with requests.Session() as s:
p = s.post(login_URL2,data=payload)
#print(p.text)
#d = s.post(req_url,files=Q)
d2 = Request("POST",req_url,files=Q)
d3 = d2.prepare()
print(d3.body.decode('utf-8'))
我相信我最不想要的是WebKitformBoundary部分,我找不到任何地方如何插入该部分。这是我第一次使用.ehtml文件进行抓取,因此,如果我遗漏了任何明显的东西,那么非常感谢所有的帮助。