1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| <?php
$im = imagegrabscreen();
class NCRSilverScraper {
// Class constructor method
function __construct() {
$this->useragent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3'; // Setting useragent of a popular browser
$handle = fopen('cookie.txt', 'w') or exit('Unable to create or open cookie.txt file.'."\n"); // Opening or creating cookie file
fclose($handle); // Closing cookie file
$this->cookie = 'cookie.txt'; // Setting a cookie file to store cookie
$this->timeout = 30; // Setting connection timeout in seconds
$this->loginUrl = 'https://mystore.ncrsilver.com/app/Account/LogOn';
}
// User login method
public function login() {
// Login values to POST as array
$emailAddress = "login";
$password="password";
$postValues = http_build_query(
array(
'username' => $emailAddress,
'password' => $password,
'RememberMe' => 'true',
'IsAjaxRequest' => 'false'
)
);
$request = $this->curlPostFields($this->loginUrl, $postValues); // Faire demande cURL POST
$login = json_decode($request); // Decoding the JSON response
if ($login->success == 1) {
// Successful login
$message = 'Successful login.'; // Assigning successful message
echo $message;
} elseif ($login->success == 0) {
$message = $login->error; // Assigning login error message returned by server
echo $message;
exit(); // Ending program
} else {
$message = 'Unknown login error.'; // Assigning unknown login error message
echo $message;
exit(); // Ending program
}
}
// User logout method
public function logout() {
$request = $this->curlPostFields('https://mystore.ncrsilver.com/app/Account/LogOff?CancelLogin=true&isAjaxRequest=true', null); // Logging out
}
// Method to search and scrape existing members details
public function scrapePersons($searchString = '') {
$searchUrl = 'https://mystore.ncrsilver.com/app/Customer/GetCustomers';
$postValues = array(
'PageRowCount' => 1000,
'RequestedPageNum' => 1,
'TotalRowCount' => -1,
'SearchArg' => $searchString,
'SortDirection' => 'ASC',
'SortColumn' => 'Name',
'page' => 1,
'start' => 0,
'limit' => 1000,
'sort' => '[{"property":"Name","direction":"ASC"}]',
'isAjaxRequest' => true,
);
$search = $this->curlPostFields($searchUrl, $postValues);
return $search;
}
// Method to make a POST request using form fields
public function curlPostFields($postUrl, $postValues) {
$_ch = curl_init(); // Initialising cURL session
// Setting cURL options
curl_setopt($_ch, CURLOPT_SSL_VERIFYPEER, FALSE); // Prevent cURL from verifying SSL certificate
curl_setopt($_ch, CURLOPT_FAILONERROR, TRUE); // Script should fail silently on error
curl_setopt($_ch, CURLOPT_COOKIESESSION, TRUE); // Use cookies
curl_setopt($_ch, CURLOPT_FOLLOWLOCATION, TRUE); // Follow Location: headers
curl_setopt($_ch, CURLOPT_RETURNTRANSFER, TRUE); // Returning transfer as a string
curl_setopt($_ch, CURLOPT_COOKIEFILE, $this->cookie); // Setting cookiefile
curl_setopt($_ch, CURLOPT_COOKIEJAR, $this->cookie); // Setting cookiejar
curl_setopt($_ch, CURLOPT_USERAGENT, $this->useragent); // Setting useragent
curl_setopt($_ch, CURLOPT_URL, $postUrl); // Setting URL to POST to
curl_setopt($_ch, CURLOPT_CONNECTTIMEOUT, $this->timeout); // Connection timeout
curl_setopt($_ch, CURLOPT_TIMEOUT, $this->timeout); // Request timeout
curl_setopt($_ch, CURLOPT_POST, TRUE); // Setting method as POST
curl_setopt($_ch, CURLOPT_POSTFIELDS, $postValues); // Setting POST fields (array)
$results = curl_exec($_ch); // Executing cURL session
curl_close($_ch); // Closing cURL session
return $results;
}
// Class destructor method
function __destruct() {
// Empty
}
}
$exec = exec ('boxcutter -f image.png'); // -f est l' option plein écran
// Let's run this baby and scrape us some data!
$testScrape = new NCRSilverScraper(); // Instantiating new object
$testScrape->login(); // Logging into server
$data = json_decode($testScrape->scrapePersons()); // Scraping people records
print_r($data);
$testScrape->logout(); // Logging out
?> |
Partager