如何获取请求中的所有POST变量

2024-10-04 11:23:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图用请求库处理一些网络抓取的东西,但我无意中发现了加密的POST数据。我想做的是通过编程找到一种方法来检索POST变量的键名,这样我就可以发送自己未过滤的值了。有没有办法做到这一点,有人能给我解释一下,或者给我指出正确的方向吗?在

import requests

s = requests.Session('http://thiswebsite.com/login', auth=('username','password'))

# Find some way to determine what k is for POST variables in k,v

params = {
    'INeedThis' : 'So I can pass this',
    'AndAlsoThis' : 'So I can pass this too',
    'AndSoOn' : 'etc'
}

x = post('http://thiswebsite.com/anotherpage', params)
print x.status_code

Tags: 数据方法网络comhttpso编程pass
1条回答
网友
1楼 · 发布于 2024-10-04 11:23:17

如果您需要POST发送的数据的名称,那么您必须首先GET这个页面并找到<input><button><text>中的{}

例如-登录页面脸谱网在

import requests

from bs4 import BeautifulSoup

r = requests.get('http://www.facebook.com/')

soup = BeautifulSoup(r.content, 'lxml')

for x in soup.find_all('form'):
    for i in x.find_all(['input', 'button', 'text']):
        print(i.name, i.get('name'))
    print(' -')

结果:

^{pr2}$

如您所见,有许多input,因此有时最好手动使用browser,并查看从浏览器到服务器的“名称”是什么:)

相关问题 更多 >