目标是收集所有阴影根的所有html。即使阴影是一个包含几个新的一次的树。我想收集它的所有HTML。就像你使用F12一样,你也可以看到所有的来源。到目前为止,我直到根:
<?php
// An example of using php-webdriver.
namespace Facebook\WebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
require_once('vendor/autoload.php');
$host = 'http://localhost:9515';//chromedriver.exe
$capabilities = DesiredCapabilities::chrome();
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
$driver->get('http://shop.polymer-project.org');
// adding cookie
$driver->manage()->deleteAllCookies();
$cookie = new Cookie('cookie_name', 'cookie_value');
$driver->manage()->addCookie($cookie);
$cookies = $driver->manage()->getCookies();
//print_r($cookies);
$driver->manage()->timeouts()->implicitlyWait(100);
// print the title of the current page
echo "The title is '" . $driver->getTitle() . "'\n";
$driver->executeScript('
var allNodes = document.getElementsByTagName(\'*\');
for (var i = 0; i < allNodes.length; i++) {
if(allNodes[i].shadowRoot) {
//alert(\'it works\'+i+allNodes[i].shadowRoot.innerHTML);
}
}
');
//$driver->quit();
?>
我得到了阴影根的代码,但是那个包含了3个阴影根。我如何收集它们并获得它的源代码。