我正在尝试学习新事物,即从另一个网站抓取数据,并且在此方面我几乎成功。但是我有一点问题。
这是我的抓取代码:
$crawler = $this->client->request('GET', 'url');
$temp = array();
$temp = $crawler->filter('table#datatable-1 tbody tr')->each(function ($node) use ($crawler) {
$out = array();
$x = explode("\n", trim($node->text(), ' '));
$out['data'] = $x;
$out['data']['attachment'] = $crawler->selectLink('Download')->link()->getUri();
return $out;
});
$push = array();
foreach($temp as $t) array_push($push, array_values(array_filter($t['data'])));
dd($push);
当我在过滤器即'id'
中使用filter('table#datatable-1 tbody tr')
抓取数据时,这是完美的工作,但是当我尝试使用'class'
即filter('table.views-table tbody tr')
抓取数据时,这不是完美的工作。
例如
我正在使用<table id="datatable-1" class="views-table cols-7 display">
上的ID
我正在使用<table class="views-table cols-7 table table-striped table-bordered table-condensed table-0" >
上的课程
请帮帮我。 预先感谢。