0

元素截图

我无法弄清楚为什么爬虫无法找到该元素。这是一个简单的元素...

我试过跑步$client->refreshCrawler()

该网站非常重 JS 和 AJAX,所以我想知道如果可能的话,内容是否可能以某种方式在隐藏的 DOM 中?

我在检查 a 标签时注意到有一个事件并且旁边有“DOM2”

这些是我测试过的所有尝试:

try {
            echo " 1 - Finding region competitions\n";
            echo $this->getCrawler()->filter('div[class="non-route race-button"]')->text();
        } catch (Exception $e) {
            echo "1 bad\n";
            echo $e->getMessage()."\n";
        }

        try {
            echo " 2 - Finding region competitions\n";
            echo $this->getCrawler()->filter('div [class="non-route race-button"]')->text();
        } catch (Exception $e) {
            echo "2 bad\n";
            echo $e->getMessage()."\n";
        }

        try {
            echo " 3 - Finding region competitions\n";
            echo $this->getCrawler()->filter('div[class=".non-route race-button"]')->text();
        } catch (Exception $e) {
            echo "3 bad\n";
            echo $e->getMessage()."\n";
        }

        try {
            echo " 4 - Finding region competitions\n";
            echo $this->getCrawler()->filter('div [class=".non-route race-button"]')->text();
        } catch (Exception $e) {
            echo "4 bad\n";
            echo $e->getMessage()."\n";
        }

        try {
            echo " 5 - Finding region competitions\n";
            $a = $this->getCrawler()->findElements(\Facebook\WebDriver\WebDriverBy::className('non-route race-button'));
            echo "NUM: ".count($a)."\n";
        } catch (Exception $e) {
            echo "5 bad\n";
            echo $e->getMessage()."\n";
        }

        try {
            echo " 6 - Finding region competitions\n";
            $b = $this->getCrawler()->findElements(\Facebook\WebDriver\WebDriverBy::className('.non-route race-button'));
            echo "NUM: ".count($b)."\n";
        } catch (Exception $e) {
            echo "6 bad\n";
            echo $e->getMessage()."\n";
        }

        try {
            echo " 7 - Finding region competitions\n";
            $c = $this->getCrawler()->findElements(\Facebook\WebDriver\WebDriverBy::tagName('data-test'));


        } catch (Exception $e) {
            echo "7 bad\n";
            echo $e->getMessage()."\n";
        }

        try {
            echo " 8 - Finding region competitions\n";
            $d = $this->getCrawler()->findElements(\Facebook\WebDriver\WebDriverBy::linkText('All Races'));
            echo "NUM: ".count($d)."\n";
        } catch (Exception $e) {
            echo "8 bad\n";
            echo $e->getMessage()."\n";
        }

        try {
            echo " 9 - Finding region competitions\n";
            return $this->getCrawler()->selectLink('All Races')->link();
        } catch (Exception $e) {
            echo "9 bad\n";
            echo $e->getMessage()."\n";
        }

        try {
            echo " 10 - Finding region competitions\n";
            $this->getCrawler()->filterXPath('/html/body/div[5]/div[1]/div[1]/div/div[4]/div/div/main/div[2]/div[2]/div/div/div/div[5]/section[1]/div/div/div[1]/div[2]/a')->click();
        } catch (Exception $e) {
            echo "10 bad\n";
            echo $e->getMessage()."\n";
        }

但每一个都返回The current node list is empty

4

1 回答 1

0

我没有等待足够长的时间来更新 DOM

sleep(3);在尝试访问元素之前使用过,现在可以正常工作

于 2020-10-05T15:37:12.293 回答