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 关注
- 101 浏览
添加回答
举报