Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method previousAll gives nodes in reverse order? #38

Open
glensc opened this issue Mar 10, 2021 · 1 comment
Open

Method previousAll gives nodes in reverse order? #38

glensc opened this issue Mar 10, 2021 · 1 comment

Comments

@glensc
Copy link
Contributor

glensc commented Mar 10, 2021

Given this code:

<?php

use Wa72\HtmlPageDom\HtmlPageCrawler;

require_once __DIR__ . '/vendor/autoload.php';

function repr1(string $html)
{
    $crawler = new htmlPageCrawler($html);
    $tags = $crawler->filter('script[src="embed.js"]');

    $tags->each(function (HtmlPageCrawler $node) {
        $before = $node->previousAll();
        print_r($before->saveHTML());
    });
}

$html = '
<script type="text/javascript" src="embed.php" ></script>
<script type="text/javascript">_load1(42); </script>

<script type="text/javascript">var c = "SPORT";</script>
<script type="text/javascript" src="embed.js"></script>
<script>_load2({width: 517, height: 323, salt: "hDPwYH3j"}); </script>
';

repr1($html);

this outputs:

<script type="text/javascript">var c = "SPORT";</script>
<script type="text/javascript">_load1(42); </script>
<script type="text/javascript" src="embed.php"></script>

but should output in dom order:

<script type="text/javascript" src="embed.php"></script>
<script type="text/javascript">_load1(42); </script>
<script type="text/javascript">var c = "SPORT";</script>

Seems the previousAll returns nodes in order closest to farthest rather first appearing in dom to last appearing in dom?

@wasinger
Copy link
Owner

The previousAll method is not a method implemented in HtmlPageCrawler but it's inherited from the base Symfony\Component\DomCrawler\Crawler class. So this problem is probably an upstream bug. Didn't find the time yet to investigate further...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants