language: PHP (php 5.4.4)
date: 252 days 19 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
 
class DevelopersUtils {
 
    public function extract($url, $value) {
 
        $dom = new DOMDocument();
 
        $file = 'content.txt';
        //$current = file_get_contents($url);
        $current = CurlTool::downloadFile($url, $file);
        //file_put_contents($file, $current);
 
        @$dom->loadHTMLFile($current);
 
        //use DOMXpath to navigate the html with the DOM
        $dom_xpath = new DOMXpath($dom);
 
        $results = $dom_xpath->query('//td1'); // (or any offending element)
        foreach ($results as $invalidNode) {
            $parentNode = $invalidNode->parentNode;
            $children = $invalidNode->childNodes;
            foreach ($children as $childNode) {
                $parentNode->insertBefore($childNode, $invalidNode);
            }
            $parentNode->removeChild($invalidNode);
        }
        
       
        //die();
        
        //$dom_xpath = new DOMXpath($dom);
        
        $elements = $dom_xpath->query("//*[text()[contains(., '" . $value . "')]]");
        var_dump($elements);
        if (!is_null($elements)) {
 
            foreach ($elements as $element) {
                var_dump($element);
                echo "\n1.[" . $element->nodeName . "]\n";
 
                $nodes = $element->childNodes;
                foreach ($nodes as $node) {
                    if (($node->nodeValue != null) && ($node->nodeValue === $value)) {
                        echo '2.' . $node->nodeValue . "\n";
                        $xpath = preg_replace("/\/text\(\)/", "", $node->getNodePath());
                        echo '3.' . $xpath . "\n";
                    }
                }
            }
        }
    }
}
 
$o = new DevelopersUtils();
 
$o->extract('http://www.price.ro/preturi_canyon_4-in-1_stylus_bundle_pack_cng-ds03_199062.htm','Canyon 4-in-1 Stylus bundle pack CNG-DS03');