Advertisement
relax4o

imotbg_scrap

Aug 9th, 2017
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. <?php
  2. header("Content-Type: text/html; charset=windows-1251");
  3.  
  4. require_once "simplehtmldom_1_5/simple_html_dom.php";
  5.  
  6. // we are using this just to get cookies
  7. $url = "https://www.imot.bg/pcgi/loginregistrations.cgi";
  8.  
  9. // path to cookie file, if not exists, we create it
  10. $cookie_file = "cookie.txt";
  11.  
  12. // login data (personal account)
  13. $email = 'relax4o92@gmail.com';
  14. $pwd = 'test12345';
  15.  
  16. function scrap_site($url, $postfields = array(), $cookie = null, $save_cookie = false, $debug = false)
  17. {
  18.     $ch = curl_init();
  19.  
  20.     curl_setopt($ch, CURLOPT_URL, $url);
  21.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  22.     curl_setopt($ch, CURLOPT_HEADER, false);
  23.  
  24.     if ( sizeof($postfields) > 0 ) {
  25.         curl_setopt($ch, CURLOPT_POST, true);
  26.         curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  27.     }
  28.  
  29.     if ( !is_null($cookie) ) {
  30.         if ( !file_exists($cookie) ) {
  31.             touch($cookie);
  32.         }
  33.  
  34.         $cookie = realpath($cookie);
  35.         if ( $save_cookie )
  36.             curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
  37.         curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
  38.     }
  39.  
  40.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  41.     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36");
  42.  
  43.     if ( $debug ) {
  44.         curl_setopt($ch, CURLOPT_VERBOSE, true);
  45.         var_dump(curl_getinfo($ch, CURLINFO_COOKIELIST));
  46.     }
  47.  
  48.     $result = curl_exec($ch);
  49.     curl_close($ch);
  50.  
  51.     return $result;
  52. }
  53.  
  54. // using this to put cookies into the cookie file
  55. scrap_site($url,
  56.             array('usr' => $email, 'pwd' => $pwd, 'mode' => 2),
  57.             $cookie_file,
  58.             true);
  59.  
  60. // and from now on we are ready to open every link
  61. // by using already saved cookies
  62. $result = scrap_site("https://www.imot.bg/pcgi/imot.cgi?act=5&adv=2c150177614666142&slink=2ysk0k&f1=1", array(), $cookie_file);
  63.  
  64. // passing the result to SimpleHTMLDom parser
  65. $html = str_get_html($result);
  66.  
  67. // extracting what we want
  68. $input = $html->find('input[name=mapn]', 0);
  69.  
  70. // and voila...
  71. echo $input->attr['value'];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement