S
S
shkiperoO2019-02-27 17:50:44
PHP
shkiperoO, 2019-02-27 17:50:44

How to decode HTML received from a parser?

It is necessary to parse a site in which information is pulled through the API and the code that comes to the parser is encoded with slashes, which is why PhantomJS filters cannot run through the elements of the received code.
Here's what comes out

<head></head><body>{"itemsLeft":1834,"html":"\r\n <!--prod-preview js-prod -->\r\n\r\n<div class="\"catalog-col\"">\r\n      <a href="\"/game/crusader-kings-ii-imperial-collection\"" class="\"catalog-card" js-prod\"="">\r\n                <span class="\"catalog-card__inner\"">\r\n          <img src="\"https://gabestore.ru/product/370x460_xJGhz-e1ruMWgPQLWxKzgpJbKr2SeHzz.jpg\"" class="\"catalog-card__img\"">\r\n                    <span class="\"catalog-card__bottom\"">\r\n                        <!-- <span class=\"catalog-card__price catalog-card__price_full\">\r\n              <span><font class=\"currencyPrice\" currency=\"250\">250</font><span class=\"rub\"><font class=\"currencySymbol\"><span class=\"rub\">P</span></font></span></span>\r\n            </span> -->\r\n            <span class="\"catalog-card__price\"">\r\n              <span><font class="\"currencyPrice\"">4395</font> <font class="\"currencySymbol\"">Р</font></span>\r\n

And here is the code
public function gabestore()
    {
        $client = Client::getInstance();
        $client->getEngine()->setPath(dirname(__FILE__) . '/bin/phantomjs.exe');
        $client->isLazy();
        $request = $client->getMessageFactory()->createRequest('https://gabestore.ru/search/next?series=&ProductFilter[sortType]=desc&loaded=0', 'GET');
        $response = $client->getMessageFactory()->createResponse();
        $client->send($request, $response);
        $html = $response->getContent();
        $crawler = new \Symfony\Component\DomCrawler\Crawler($html);
        $stripped = $html;
        stripcslashes($stripped);
        $b = html_entity_decode($stripped);
        stripcslashes($b);
        dd($b);
//        $crawler->filter('.catalog-col')->each(function($str) {
//            $str->attr('href');
//
//            dd($str);
//        });

    }

This is how the code looks like if it is not passed through the decoding functions
<head></head><body>{"itemsLeft":1834,"html":"\r\n <!--prod-preview js-prod -->\r\n\r\n<div class="\&quot;catalog-col\&quot;">\r\n

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2019-02-27
@shkiperoO

stripcslashes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question