parser.php 713 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. class DomDocumentParser {
  3. private $doc;
  4. public function __construct($url)
  5. {
  6. $options = array(
  7. 'http' => array(
  8. 'method' => 'GET',
  9. 'header' => 'User-Agent: voogleBot/0.1\n'
  10. )
  11. );
  12. $context = stream_context_create($options);
  13. $this->doc = new DomDocument();
  14. return @$this->doc->loadHTML(file_get_contents($url, false, $context));
  15. }
  16. public function getLinks()
  17. {
  18. return $this->doc->getElementsByTagName('a');
  19. }
  20. public function getTitleTag()
  21. {
  22. return $this->doc->getElementsByTagName('title');
  23. }
  24. public function getMeta()
  25. {
  26. return $this->doc->getElementsByTagName('meta');
  27. }
  28. public function getImages()
  29. {
  30. return $this->doc->getElementsByTagName('img');
  31. }
  32. }