Advertisement
niammuddin

DOMDocument

Dec 22nd, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1.  
  2.  
  3. <?php
  4. function curl($url){
  5. // inisialisasi CURL
  6. $data = curl_init();
  7. // setting CURL
  8. curl_setopt($data, CURLOPT_URL, $url);
  9. curl_setopt($data, CURLOPT_HEADER, 0);
  10. curl_setopt($data, CURLOPT_RETURNTRANSFER, 1);
  11. curl_setopt($data, CURLOPT_URL, $url);
  12. // menyamar menjadi bing
  13. curl_setopt($data, CURLOPT_REFERER, 'https://www.google.com');
  14. curl_setopt($data, CURLOPT_SSL_VERIFYPEER, false);
  15. // agar tidak di curigai oleh bing
  16. curl_setopt($data, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
  17. curl_setopt($data, CURLOPT_FOLLOWLOCATION, true);
  18. // menjalankan CURL untuk membaca isi file
  19. $response = curl_exec($data);
  20. curl_close($data);
  21. return $response;
  22. }
  23.  
  24. // proses
  25. $url = 'http://keepvid.com/?url=https://www.youtube.com/watch?v=Z62eeT0bXuk';
  26. $feed = curl($url);
  27. $content = explode('<div class="d-info2"><dl>',$feed);
  28. $content = explode('</dl></div>',$content[1]);
  29. $content = htmlspecialchars_decode($content[0]);
  30. //$content = str_replace(['var __mxmProps = {"pageProps":{"pageName":"trending-page"}};var __mxmState = ',';'], '', $content);
  31.  
  32.  
  33. //hasil
  34. //echo $content;
  35.  
  36. //$api = file_get_contents(''.$content.'');
  37. //$json = json_decode($content,true);
  38. //foreach ($json['page']['tracks']['list'] as $as){
  39.  
  40. //print_r($as);
  41.  
  42. //echo ''.$as['name'].'<br/>';
  43. //echo ''.$as['artistName'].'<br/>';
  44. //echo ''.$as['commontrackVanityId'].'<br/>';
  45. //echo ''.$as['albumCoverart350x350'].'<br/>';
  46.  
  47. //}
  48.  
  49.  
  50. $doc = new DOMDocument();
  51. $doc->loadHTML($content);
  52. $anchors = $doc->getElementsByTagName('a');
  53. foreach($anchors as $node) {
  54. echo $node->textContent;
  55. if ($node->hasAttributes()) {
  56. foreach($node->attributes as $a) {
  57. echo ' | '.$a->name.': '.$a->value.'<br/><hr/>';
  58. }
  59. }
  60. }
  61.  
  62. ?>
  63.  
  64.  
  65. <hr/>
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. <?php
  73. preg_match_All("#<a\s[^>]*href\s*=\s*[\'\"]??\s*?(?'path'[^\'\"\s]+?)[\'\"\s]{1}[^>]*>(?'name'[^>]*)<#simU", $content, $hrefs, PREG_SET_ORDER);
  74.  
  75. foreach ($hrefs AS $urls){
  76. print $urls['path']."<br><hr/>";
  77. }
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement