-1
我希望我的網站能夠從此頁上刮取信息beta.tfgm.com/public-transport/tram/stops/oldham-central-tra m特別我想從該網站刮目的地和到期時間,並給我一個輸出。Laravel Guzzle從頁面獲取目的地和到期時間
這時我的控制器看起來是這樣的:
function guzzle(){
$client = new \GuzzleHttp\Client();
$results = $client->get('https://beta.tfgm.com/public-transport/tram/stops/oldham-central-tram');
//$result->getBody();
//return view('hello')->with('results', $results);
//dd($result);
$results->getBody()->getContents();
dd($results);
return view('hello');
}
,輸出是:
Response {#190 ▼
-reasonPhrase: "OK"
-statusCode: 200
-headers: array:8 [▼
"Content-Security-Policy" => array:1 [▶]
"Content-Type" => array:1 [▶]
"Date" => array:1 [▶]
"ETag" => array:1 [▶]
"X-Content-Security-Policy" => array:1 [▶]
"X-WebKit-CSP" => array:1 [▶]
"Content-Length" => array:1 [▶]
"Connection" => array:1 [▶]
]
-headerNames: array:8 [▼
"content-security-policy" => "Content-Security-Policy"
"content-type" => "Content-Type"
"date" => "Date"
"etag" => "ETag"
"x-content-security-policy" => "X-Content-Security-Policy"
"x-webkit-csp" => "X-WebKit-CSP"
"content-length" => "Content-Length"
"connection" => "Connection"
]
-protocol: "1.1"
-stream: Stream {#188 ▶}
}
但是我怎麼可以訪問特定HTML類,從它刮信息,並輸出它在我的頁?
我得到:GuzzleHttp \ PSR7 \ Stream對象([流:GuzzleHttp \ PSR7 \流:民營] =>資源ID#238 [大小:GuzzleHttp \ Psr7 \ Stream:private] => [可尋找:GuzzleHttp \ Psr7 \ Stream:private] => 1 [可讀:GuzzleHttp \ Psr7 \ Stream:private] => 1 [可寫:GuzzleHttp \ Psr7 \ Stream:private] => 1 [uri:GuzzleHttp \ Psr7 \ Stream:private] => php:// temp [customMetadata:GuzzleHttp \ Psr7 \ Stream:private] => Array()) – Przemek
我編輯了我的帖子。 – Nenroz
真棒如何才能保持特定的數據,所以我想只保留表而不是整個頁面?你可以喜歡只設置一張桌子嗎? – Przemek