1 回答

TA貢獻1827條經(jīng)驗 獲得超9個贊
當您向服務器發(fā)出HTTP 請求時,該服務器會將呈現(xiàn)的網(wǎng)頁返回給該用戶。這意味著requests將得到正確的響應。
但是,當您在瀏覽器中打開網(wǎng)頁時,您正在向該服務器發(fā)出新請求,該服務器將再次呈現(xiàn)該頁面。由于這次您沒有傳遞$_REQUEST['iv']etc. 值,因此該表將顯示為空白。
您有幾個選項,具體取決于您要執(zhí)行的操作:
將信息存儲在數(shù)據(jù)庫中
您可以將該信息存儲在數(shù)據(jù)庫中。例如,一些數(shù)據(jù)庫是SQLite3或MySQL。我省略了確切的數(shù)據(jù)庫插入/讀取實現(xiàn),因為它在您選擇的數(shù)據(jù)庫之間有所不同。
一個簡單的方法可能是:
<?php
$iv=$_REQUEST['iv'];
// insert other variables etc.
// Check if this is a POST request
if ($_SERVER['REQUEST_METHOD'] === "POST") {
// INSERT DATA INTO YOUR DATABASE AS APPROPRIATE
// You can also echo back the table if you want
// Else it might be a GET request
} elseif ($_SERVER['REQUEST_METHOD'] === "GET") {
// READ DATA FROM DATABASE
// echo table with the data from the database
}
?>
使用網(wǎng)址參數(shù)
或者,您可以使用URL 參數(shù)對數(shù)據(jù)進行編碼,如下所示:
# In your Python code
# Notice that requests.post changed to requests.get and data changed to params
r = requests.get('http://localhost/index.php', params={"iv":a,"ven":b,"hem":c,"card":d,"ecg":e})
# You can now access this specific URL to see the populated table
# The URL will look something like http://localhost/index.php?iv=a&ven=b/
print(r.url)
請注意,這需要您訪問該特定 URL,并且如果您訪問沒有參數(shù)的基本 URL(即 )則不起作用https://localhost/index.php。
添加回答
舉報