Advertisement
Guest User

Untitled

a guest
Dec 5th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2.  
  3. //db
  4.  
  5. $servername = "localhost";
  6. $username = "root";
  7. $password = "root";
  8. $dbname = "celebheight";
  9.  
  10. // Create connection
  11. $conn = new mysqli($servername, $username, $password, $dbname);
  12. // Check connection
  13. if ($conn->connect_error) {
  14. die("Connection failed: " . $conn->connect_error);
  15. }
  16.  
  17. // unicode
  18. $conn->set_charset("utf8");
  19.  
  20. $sql_key = 'SELECT id, name FROM links where run = 0 limit 1';
  21. $st = $conn->prepare($sql_key);
  22. $st->execute();
  23. $st->bind_result($_id, $_name);
  24. while ($st->fetch()){
  25.  
  26. }
  27.  
  28. $stud = $conn->prepare('UPDATE `links` SET `run` = 1 WHERE `links`.`id` = ?;');
  29. $stud->bind_param('i',$_id);
  30. $stud->execute();
  31.  
  32. include('../simple_html_dom.php');
  33. header('Content-Type: text/html; charset=utf-8');
  34. $key = 'who is '.$_name;
  35. $key = str_replace(' ','-',$key);
  36. $page = 'https://www.google.com.vn/search?q='.$key.'&oq='.$key.'&hl=en';
  37.  
  38. $html = file_get_html($page);
  39.  
  40. $name_ob = $html->find('div[class=_B5d]',0);
  41. $decription_ob = $html->find('div[class=_tXc] span',0);
  42. $height_ob = $html->find('span[class="_tA"]',1);
  43.  
  44. $also_search_ob = $html->find('div[class=_rvh]',1)->find('div[class=_wSe] a[class="fl"]');
  45.  
  46. $name = str_replace('&#8209;',' ',$name_ob->innertext);
  47. $name = str_replace('-',' ',$name);
  48. $decription = str_replace('Wikipedia','',$decription_ob->plaintext);
  49. $height = iconv("ISO-8859-1", "UTF-8", $height_ob->innertext);
  50.  
  51. $sql = 'INSERT INTO links (name,run) VALUES (?,1)';
  52. $stmt = $conn->prepare($sql);
  53. $stmt->bind_param('s',$name);
  54. $stmt->execute();
  55. $stmt->close();
  56.  
  57. foreach ($also_search_ob as $item){
  58. if(!strpos($item->innertext, '...')){
  59. $name = str_replace('&#8209;',' ',$item->innertext);
  60. $name = str_replace('-',' ',$name);
  61. $sql = 'INSERT INTO links (name) VALUES (?)';
  62. $stmt = $conn->prepare($sql);
  63. $stmt->bind_param('s',$name);
  64. $stmt->execute();
  65. $stmt->close();
  66. }
  67.  
  68. }
  69. $conn->close();
  70. echo 'done';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement