Bunkertor 7 Posted December 9, 2010 Report Share Posted December 9, 2010 Sveiki, Meeginu uzskriptot skriptu, kas paraadiitu, vai attieciigaa HTML dokumentaa atrodas links uz kaadu konkreetu resursu. Piemeeram, skripts aiziet uz vilks.lv un paarbauda, vai kaut kur kodaa ir links uz lacis.lv Es saakumaa domaaju, ka to var izdariit ar $xpath->query paliidziibu, bet jo vairaak manuaalus lasu, jo paarliecinos, ka laikam nevar. Ideja bija kaut kaa taa: <?php $doc = DOMDocument::loadHTMLFile('http://www.whatever'); $xpath = new DOMXPath($doc); $links = $xpath->query('//a/@href/MyKeyWordInTheURL'); #$urlz = array(); foreach ($links as $link) { # $urlz[] = $link->value; echo $link->value . "\n"; echo "Linka Teksts:" . $link->nodeValue . "\n"; } ?> Varbuut labaak meeginaat ar Preg Match? Quote Link to comment Share on other sites More sharing options...
indoom Posted December 9, 2010 Report Share Posted December 9, 2010 if (strpos(file_get_contents('http://vilks.lv'), 'href="http://lacis.lv') !== false) { /// oh yeah } Quote Link to comment Share on other sites More sharing options...
Kaklz Posted December 9, 2010 Report Share Posted December 9, 2010 cerams, ka domu uztversiet. indoom: <!--<a href="http://lacis.lv">test</a>--> Bunkertor7: <a href="http://lacis.lv" style="display:none">test</a> Quote Link to comment Share on other sites More sharing options...
indoom Posted December 9, 2010 Report Share Posted December 9, 2010 (edited) if (strpos(strip_tags(file_get_contents('http://vilks.lv'),'<a>'), 'href="http://lacis.lv') !== false) { /// oh yeahhhhh } Pret to display:none tāpat neko neizdarīs. To jau var ielikt cssā. Edited December 9, 2010 by indoom Quote Link to comment Share on other sites More sharing options...
Bunkertor 7 Posted December 9, 2010 Author Report Share Posted December 9, 2010 mhm... paldies par idejaam, bet es tomeer gribeetu meeginaat to izdariit ar DOM paliidziibu, es tikai nezinu, vai ar "query" paliidziibu var kaut ko mekleet Quote Link to comment Share on other sites More sharing options...
marrtins Posted December 9, 2010 Report Share Posted December 9, 2010 Piemērs ar simplexml. Noteikti var izdarīt arī ar DOM query, bet negribas tagad testēt. <?php $doc = DOMDocument::loadHTMLFile('http://www.whatever'); $xpath = new DOMXPath($doc); $xml = simplexml_import_dom($doc); $links = $xml->xpath("//a[@href='http://vilks.lv/']"); var_dump($links); foreach($links as $link){ print $link['href']."\n"; } Es gan to href apstrādātu ar PHP, t.i., $xml->xpath("//a"); un tad tajā ciklā parsētu href. Mazums tur kaut-kādi www. vai path galā... XPath, protams, ir arī "contains" - check w3schools. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.