Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <?php
  2. header('Content-Type: text/html; charset=utf-8');
  3. $grep = new DoMDocument();
  4. @$grep->loadHTMLFile("https://www.postme.com.my/men-1.html");
  5.  
  6. $finder = new DomXPath($grep);
  7. $classCat = "level0 nav-1 active parent";
  8.  
  9. $nodesCat = $finder->query("//*[contains(@class, '$classCat')]");
  10.  
  11. $i = 0;
  12.  
  13. foreach ($nodesCat as $node) {
  14. $span = $node->childNodes;
  15. $replace = str_replace("Items 1-12 of", "",$span->item(1)->nodeValue);
  16.  
  17. echo $replace. " : ";
  18. }
  19.  
  20. // Check another link using class name of "level0 nav-2 active parent"
  21. //repeat code
  22.  
  23. @$grep->loadHTMLFile("https://www.postme.com.my/women.html");
  24.  
  25. $finder = new DomXPath($grep);
  26. $classCat = "level0 nav-2 active parent";
  27.  
  28. $nodesCat = $finder->query("//*[contains(@class, '$classCat')]");
  29.  
  30. $i = 0;
  31.  
  32. foreach ($nodesCat as $node) {
  33. $span = $node->childNodes;
  34. $replace = $span->item(1)->nodeValue;
  35.  
  36. echo $replace. " : ";
  37. }
  38. //check another link with class name "level0 nav-3 active parent".
  39. //notice the incrementing nav-#?
  40. //I don't want to make the code long just because each link is using a slightly different class name to refer to the data.
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement