Laravel Guzzle从页面获取目的地和预定时间 [英] Laravel Guzzle getting destination and due time from a page
本文介绍了Laravel Guzzle从页面获取目的地和预定时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的网站从此页面抓取信息beta.tfgm.com/public-transport/tram/stops/oldham-central-tram,尤其是我要从该网站抓取目的地和到期时间,并提供我的输出.
I want my website to scrape information from this page beta.tfgm.com/public-transport/tram/stops/oldham-central-tram and in particular I want to scrape destination and due time from that website and give me an output.
此刻,我的控制器如下所示:
At this moment my controller looks like this:
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类,从中获取信息并将其输出到我的页面上?
However how can I access specific html class, scrape information from it and output it on my page?
推荐答案
dd
在这里对您没有用,请尝试以下方法:
dd
is not useful for you here, try this :
$client = new \GuzzleHttp\Client();
$results = $client->get('https://beta.tfgm.com/public-transport/tram/stops/oldham-central-tram');
print_r($results->getBody()->getContents()); // The HTML content
这篇关于Laravel Guzzle从页面获取目的地和预定时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文