亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 cURL 從頁面獲取文本

如何使用 cURL 從頁面獲取文本

PHP
aluckdog 2023-11-03 16:48:06
我最近需要制作一個 PHP 文件從頁面中獲取文本并顯示它,但我不知道該怎么做。我當前的代碼是:https://pastebin.com/Zhh4SS3L        $results["registeredname"] = "here shall be the domain";    $results["productname"] = "this shall be fetched";    $results["productid"] = "5";    $results["billingcycle"] = "Monthly";    $results["validdomains"] = $this->getHostDomain();    $results["validips"] = $this->getHostIP();    $results["validdirs"] = $this->getHostDir();    $results["checkdate"] = Carbon::now()->toDateString();    $results["version"] = "this shall be fetched";    $results["regdate"] = "this shall be fetched";    $results["nextduedate"] ="this shall be fetched";;    $results["addons"] = array(array('name' => 'Branding Removal', 'nextduedate' => "this shall be fetched";', 'status' 任何建議都很好!
查看完整描述

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);

}

你可以用它來輕松抓取東西,所以我想你可以使用它。


希望這可以幫助您或為您指明正確的方向:)


查看完整回答
反對 回復 2023-11-03
  • 1 回答
  • 0 關注
  • 145 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號