1 回答

TA貢獻1856條經驗 獲得超17個贊
這讓我想起去年玩的一個東西。因為我沒有您計劃獲取的確切值。我將向您展示我使用 cURL 進行操作的示例。應該有幫助。
我對我的網站進行了一些更改,所以它可能不再返回任何內容(但誰知道哈哈),但我知道它對我有用,所以重點仍然存在。
它的基本要點是 - 輸入一個頁面,發布搜索的術語,返回頁面上的任何內容。除了您想要的之外,這還將向 URL POST 一個值,但您可以跳過 POST 部分。如果數據是在登錄或其他東西后面。
/*
* TESTING GROUNDS
*
* A. Goal: Search (toms.click/search) and return found articles page
* website = toms.click
*
* word to search for (1 match): axiom
*
* condition for submit:
* if (isset($_POST['searchSubmit']) && isset($_POST['searchbar'])) { ... }
* → ['searchSubmit' => 'GO', 'searchbar' => 'axiom']
*
*
* form layout:
* <form method="POST" action="https://toms.click/search">
<input class="search-bar" type="search" name="searchbar" placeholder="Search" minlength="3" title="search the website" required=""><!--
whitespace removal between searchbar and submit
--><input class="submit" name="searchSubmit" type="submit" value="Go">
</form>
*
/**
* @param $searchbar string whatever you'd type into the searchbar
* @return string
*/
function remoteSearch($searchbar)
{
$url = 'https://toms.click/search'; //The URL of what you want to fetch / enter / post to
/** @var array $fields what we're going to post, $fields['a'] = 'b' is $_POST['a'] = 'b' */
$fields = array(
'searchSubmit' => 'GO',
'searchbar' => $searchbar
);
$ch = curl_init();
//Set our target url (login script)
curl_setopt($ch, CURLOPT_URL, $url);
//Enable post and load a post query
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
//HTTPs, don't verify it for now
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//Enable up to 10 redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
//We want whatever is on the other side
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return curl_exec($ch);
}
你可以用它來輕松抓取東西,所以我想你可以使用它。
希望這可以幫助您或為您指明正確的方向:)
- 1 回答
- 0 關注
- 145 瀏覽
添加回答
舉報