Answer the question
In order to leave comments, you need to log in
Why doesn't element search work (DiDOM library)?
Good afternoon. I'm trying to parse a page using GuzzleHttp and DiDOM .
First I find a group of elements. Then, inside each found element, you need to search.
$sportPage = $client->request('GET', 'Адрес сайта');
$response = (string) $sportPage->getBody();
$document = new DiDom\Document($response);
$cometitionQuery = $document->find('.родительский класс');
foreach ($cometitionQuery as $item)
{
//Ругается на строчку ниже
$competitionName = $item->find('.класс внутри выборки')->html();
$competition[] = $competitionName;
}
Call to a member function html() on array
Answer the question
In order to leave comments, you need to log in
I do not know this library, but I do not think that it is fundamentally different from others. It also shows you an error that the method html()
cannot be called on an array. By the method find()
you get an array, even if it finds only one element, it will still be an array. Try like this:
.....
$competitionName = $item->find('.класс внутри выборки')[0]->html();
.....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question