1 回答

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個(gè)贊
這讓我想起去年玩的一個(gè)東西。因?yàn)槲覜]有您計(jì)劃獲取的確切值。我將向您展示我使用 cURL 進(jìn)行操作的示例。應(yīng)該有幫助。
我對我的網(wǎng)站進(jìn)行了一些更改,所以它可能不再返回任何內(nèi)容(但誰知道哈哈),但我知道它對我有用,所以重點(diǎn)仍然存在。
它的基本要點(diǎn)是 - 輸入一個(gè)頁面,發(fā)布搜索的術(shù)語,返回頁面上的任何內(nèi)容。除了您想要的之外,這還將向 URL POST 一個(gè)值,但您可以跳過 POST 部分。如果數(shù)據(jù)是在登錄或其他東西后面。
/*
* 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);
}
你可以用它來輕松抓取東西,所以我想你可以使用它。
希望這可以幫助您或?yàn)槟该髡_的方向:)
- 1 回答
- 0 關(guān)注
- 157 瀏覽
添加回答
舉報(bào)