Note that there are some explanatory texts on larger screens.

plurals
  1. PODOMDocument XPath
    text
    copied!<p>Can somebody show me some examples to import a html-page and use the XPath to find the keywords including the rest of the text from the div, p, title etc.</p> <p>Thank you!</p> <p>EDIT:</p> <p>In this case i use my webcrawler for example, i have a form to get the website to be crawled and the keywords wich has to be find in pages of the website.</p> <pre><code>http://crawler.tmp.remote.nl/example.php </code></pre> <p>Now it scans for webpages with the keywords inside, my problem.. I need the div area around the founded keywords.</p> <pre><code>class MyCrawler extends PHPCrawler { function handlePageData(&amp;$page_data) { // CHECK DOMEIN $domain = $_POST['domain']; $keywords = $_POST['keywords']; //$tags = get_meta_tags($page_data["url"]); //$iKeyFound = null; $find = $keywords; $str = file_get_contents($page_data["url"]); if(strpos($str, $find) == true) { echo $page_data["referer_url"]. ' - gevonden'; $keywords = $_POST['keywords']; if($page_data["header"]){ echo "&lt;table border='1' &gt;"; echo "&lt;tr&gt;&lt;td width='300'&gt;Status:&lt;/td&gt;&lt;td width='500'&gt; ".strtok($page_data["header"], "\n")."&lt;/td&gt;&lt;/tr&gt;";} else "&lt;table border='1' &gt;"; // PRINT EERSTE LIJN echo "&lt;tr&gt;&lt;td&gt;Page requested:&lt;/td&gt;&lt;td&gt; ".$page_data["url"]."&lt;/td&gt;&lt;/tr&gt;"; // PRINT STATUS WEBSITE // PRINT WEBPAGINA echo "&lt;tr&gt;&lt;td&gt;Referer-page:&lt;/td&gt;&lt;td&gt; ".$page_data["referer_url"]."&lt;/td&gt;&lt;/tr&gt;"; // CONTENT ONTVANGEN? if ($page_data["received"]==true) echo "&lt;tr&gt;&lt;td&gt;Content received: &lt;/td&gt;&lt;td&gt;".$page_data["bytes_received"] / 8 . " Kbytes&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;"; else echo "&lt;tr&gt;&lt;td&gt;Content:&lt;/td&gt;&lt;td&gt; Not received&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;"; $domain = $_POST['domain']; $link = mysql_connect('localhost', 'crawler', '--'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("crawler"); if(empty($page_data["referer_url"])) $page_data["referer_url"] = $page_data["url"]; strip_tags($str, '&lt;p&gt;&lt;b&gt;'); $matches = $keywords; //$match = preg_match_all("'/&lt;(*.?)(*.?)&gt;(*.?)'".$keywords."'(*.?)&lt;\/($1)&gt;/'", $str, $matches, PREG_SET_ORDER); //echo $match; mysql_query("INSERT INTO crawler (id, domain, url, keywords, data) VALUES ('', '".$page_data["referer_url"]."', '".$page_data["url"]."', '".$keywords."', '".mysql_real_escape_string($str) . "' )"); echo '&lt;br&gt;'; echo "&lt;br&gt;&lt;br&gt;"; echo str_pad(" ", 5000); // "Force flush", workaround flush(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload