我正在嘗試填寫 html 表單并獲得我在手動填寫時獲得的預期結果。但我失敗了。
我正在嘗試https://www.desco.org.bd/ebill/login.php用 value填充網站32000001。到目前為止,我的嘗試如下 -
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)
我發現login.php重定向到authentication.php并且它進一步重定向到billinformation.php提供我需要的真實資料。
提前致謝。
注意我不打算使用 selenium,因為它對我的情況來說太慢了,即從這個站點收集大量資料。
uj5u.com熱心網友回復:
我正在處理類似的情況,您可能會嘗試使用 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
uj5u.com熱心網友回復:
另一個嘗試:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/422164.html
標籤:
