Advertisement
m4ly

Briefing.com Calendar

Sep 23rd, 2013
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.28 KB | None | 0 0
  1. <?php
  2. /*
  3. Author: Dawid Mocek <[email protected]>
  4. Reqs: php_curl, php_regex extensions.
  5.  
  6. Define $user & $pass which u enter in these textboxes: https://www.briefing.com/Login/subscriber.aspx
  7. This script will log in you and logout
  8.  
  9. !  HTML will be in $out variable, parse it using appropriate way ( NOT REGEX as I programmed below) !
  10. */
  11.                 $user = "[email protected]";
  12.                 $pass =  "pass";
  13.  
  14.                 $ch = curl_init();
  15.                 $date = new DateTime();
  16.                 $date_sql = $date->format('Y-m-d');
  17.  
  18.                 $post_data = "__EVENTTARGET=_buttonLogin&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwULLTE0MDU4NzM3MTRkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYDBRNfY2hlY2tCb3hSZW1lbWJlck1lBQxfYnV0dG9uTG9naW4FF19idXR0b25Mb2dpblByb2R1Y3RQaWNr&__EVENTVALIDATION=%2FwEWBgL16NeiBQKizoWDAgLp7cFvAvap%2F9sEArn4h%2BwMArKz36IF&_textBoxUserName=".$user."&_textBoxPassword=".$pass."&_checkBoxRememberMe=on";
  19.                 $headers = array(
  20.                     "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  21.                     "Accept-Language: pl,en-us;q=0.7,en;q=0.3",
  22.                     "Accept-Encoding: gzip, deflate"
  23.                 );
  24.  
  25.                 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0.1");
  26.                 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  27.  
  28.                 // Login
  29.                 curl_setopt($ch, CURLOPT_URL, "https://www.briefing.com/Login/subscriber.aspx");
  30.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  31.                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  32.                 curl_setopt($ch, CURLOPT_POST, 1);
  33.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  34.                 curl_setopt($ch, CURLOPT_COOKIEFILE, './cookie.txt');
  35.                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  36.                 $login = curl_exec($ch);
  37.                 $login = null;
  38.                 // Get account profile
  39.                 // curl_setopt($ch, CURLOPT_URL,"https://www.briefing.com/investor/Emails/EditMyProfile.aspx");
  40.                 // $acct_profile = curl_exec($ch);
  41.                 // print_r($acct_profile);
  42.                 //
  43.                 // Get calendar
  44.                 curl_setopt($ch, CURLOPT_URL, "http://www.briefing.com/investor/calendars/earnings/" . $date->format('Y/m/d') . "/");
  45.                 $out = curl_exec($ch);
  46.  
  47.                 // Logout
  48.                 curl_setopt($ch, CURLOPT_URL, "https://www.briefing.com/Login/Logout.aspx");
  49.                 $logout = curl_exec($ch);
  50.                 $logout = null;
  51.                 curl_close($ch);
  52.  
  53.                 $sql = new mysqli("localhost", "user", "pass", "db");
  54.                 /*
  55.                 $stmtd = $sql->prepare("DELETE FROM earnings_briefing WHERE data = ?");
  56.                 $stmtd->bind_param('s', $date->format('Y-m-d');
  57.                 $stmtd->execute();
  58.                 */
  59.                 $stmti = $sql->prepare("INSERT INTO earnings_briefing (stage, data, ticker) VALUES(?,?,?)");
  60.                 $match = array();
  61.                 $before_tickers = array();
  62.                 if (preg_match("/Before The Open<\/th>(.*?)<thead>|Before The Open<\/th>(.*?)<\/table>/ms", $out, $match)) {
  63.                     preg_match_all("/<a\s+class=\"ticker\".*>(.*?)<\/a>/", $match[0], $before_tickers);
  64.  
  65.               $stage = 'BMO';
  66.                     if (!empty($before_tickers[1])) {
  67.                         foreach($before_tickers[1] as $ticker) {
  68.                          $stmti->bind_param('sss', $stage, $date_sql, $ticker);
  69.                          $stmti->execute();
  70.                         }
  71.  
  72.                     }
  73.                 }
  74.  
  75.                 $after_tickers = array();
  76.                 $stage = 'AMC';
  77.                 if (preg_match("/After The Close<\/th>(.*?)<\/tr><\/table>/ms", $out, $match)) {
  78.                     preg_match_all("/<a\s+class=\"ticker\".*>(.*?)<\/a>/", $match[1], $after_tickers);
  79.                     if (!empty($after_tickers[1])) {
  80.                     foreach($after_tickers[1] as $ticker) {
  81.                          $stmti->bind_param('sss', $stage, $date_sql, $ticker);
  82.                          $stmti->execute();
  83.                         }
  84.                     }
  85.                 }
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement