Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header("Content-Type: text/html; charset=windows-1251");
- require_once "simplehtmldom_1_5/simple_html_dom.php";
- // we are using this just to get cookies
- $url = "https://www.imot.bg/pcgi/loginregistrations.cgi";
- // path to cookie file, if not exists, we create it
- $cookie_file = "cookie.txt";
- // login data (personal account)
- $email = 'relax4o92@gmail.com';
- $pwd = 'test12345';
- function scrap_site($url, $postfields = array(), $cookie = null, $save_cookie = false, $debug = false)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HEADER, false);
- if ( sizeof($postfields) > 0 ) {
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
- }
- if ( !is_null($cookie) ) {
- if ( !file_exists($cookie) ) {
- touch($cookie);
- }
- $cookie = realpath($cookie);
- if ( $save_cookie )
- curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
- }
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- 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");
- if ( $debug ) {
- curl_setopt($ch, CURLOPT_VERBOSE, true);
- var_dump(curl_getinfo($ch, CURLINFO_COOKIELIST));
- }
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
- }
- // using this to put cookies into the cookie file
- scrap_site($url,
- array('usr' => $email, 'pwd' => $pwd, 'mode' => 2),
- $cookie_file,
- true);
- // and from now on we are ready to open every link
- // by using already saved cookies
- $result = scrap_site("https://www.imot.bg/pcgi/imot.cgi?act=5&adv=2c150177614666142&slink=2ysk0k&f1=1", array(), $cookie_file);
- // passing the result to SimpleHTMLDom parser
- $html = str_get_html($result);
- // extracting what we want
- $input = $html->find('input[name=mapn]', 0);
- // and voila...
- echo $input->attr['value'];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement