Exemplo n.º 1
0
function AddIDs($node, $father)
{
    if ($node->nodeType !== XML_ELEMENT_NODE) {
        return;
    }
    $arr = array();
    foreach ($node->childNodes as $childNode) {
        $index = CountInArray($arr, $childNode->nodeName);
        $arr[] = $childNode->nodeName;
        $childNode = AddIDs($childNode, $father . "_" . $childNode->nodeName . ($index + 1));
    }
    $node->removeAttribute('class');
    $node->removeAttribute('id');
    $node->setAttribute('id', str_replace("_body1_", "", $father));
    return $node;
}
Exemplo n.º 2
0
if (strtolower(substr($url, 0, 3)) == "www") {
    $url = "http://" . $url;
}
$xpath = new DOMXPath($doc);
$isOUR = "";
if (strpos($url, "www.dlib.org") !== false) {
    $isOUR = "dlib";
} elseif (strpos($url, "rivista-statistica.unibo.it") !== false) {
    $isOUR = "RS";
} elseif (strpos($url, "almatourism.unibo.it") !== false) {
    $isOUR = "AM";
} elseif (strpos($url, "antropologiaeteatro.unibo.it") !== false) {
    $isOUR = "AT";
}
try {
    $doc = AddIDs($doc->getElementsByTagName('html')->item(0), "");
} catch (Exception $e) {
    echo "Indirizzo non raggiungibile.";
    exit;
}
switch ($isOUR) {
    case "dlib":
    case "dlib2":
        $contentTable = $doc->getElementsByTagName('table')->item(8);
        // Prendo la tabella di posizione 8
        break;
    case "RS":
    case "AM":
    case "AT":
        $contentTable = $xpath->query("//*[@id='div1_div2_div2_div3']", $doc)->item(0);
        break;