[英]Can not fill form using python requests
I am trying to fill html form and get the intended result as i get when i fill manually.我正在尝试填写 html 表格并获得我在手动填写时得到的预期结果。 But I fail.
但我失败了。
I am trying to fill the site https://www.desco.org.bd/ebill/login.php
with value 32000001
.我正在尝试用值
32000001
填充站点https://www.desco.org.bd/ebill/login.php
。 So far my try is as below-到目前为止,我的尝试如下 -
import requests
#LOGIN_URL = 'https://www.desco.org.bd/ebill/login.php'
#LOGIN_URL = 'https://www.desco.org.bd/ebill/authentication.php'
LOGIN_URL = 'https://www.desco.org.bd/ebill/billinformation.php'
payload = {
'username': '32000001',
'login':'Login',
'login':'true'
}
with requests.Session() as s:
p = s.post(LOGIN_URL, data=payload)#, verify=False)
# print the html returned or something more intelligent to see if it's a successful login page.
print (p.text)
I have found that login.php
redirects to authentication.php
and it further redirects to billinformation.php
which delivers the true data i needed.我发现
login.php
重定向到authentication.php
并进一步重定向到billinformation.php
,它提供了我需要的真实数据。
Thanks in advance.提前致谢。
NB I am not planning to use selenium since it is too slow for my case ie collect huge data from this site.注意我不打算使用 selenium 因为它对我的情况来说太慢了,即从这个站点收集大量数据。
i am working for similar case, may be you would try using websockets:我正在处理类似的情况,您可能会尝试使用 websockets:
import websockets
def process_function(message):
# process the message
def server(ws:str, path:int):
while True:
message_received = await ws.recv() # receive from ui
print(f'Msg [{message_received}]')
message_to_send = process_function(message)
await ws.send(message_to_send) # send feedback to ui
server = websockets.serve(server, '127.0.0.1', 5678) # set the html to run in the same ip:port
another try:另一个尝试:
import json, requests
def do_auth(url):
headers = {"Content-Type": "application/json", "Accept":'*/*'}
body = json.dumps({'username': 'user', 'password': 'pass'})
r = requests.post(url=url, headers=headers, data=body, verify=False)
print(r.status_code);
d = json.loads(r.text);
print(d['access_token']);
print(d['refresh_token'])
return d['access_token'], d['refresh_token']
do_auth(url_auth) # authorization
requests.get(url_content, headers=headers, verify=False) # get data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.