Make bot login to encrypted site
I am building a bot that scrapes data from a secure page www.jtracker.com.
my problem is that i need my bot to login (with a fixed username and
password) so that i can scrape the data. i began by setting up something
with php/curl. I think I'm having trouble with the cookies. any advice??
$data_array['username'] = $_POST['username'];
$data_array['password'] = $_POST['password'];
$account = $_POST['accounts'];
$type = $_POST['type'];
$target = "https://www.jtracker.com/account/login.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target); // Define target site
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01;
Windows NT 5.0)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Return page in string
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirects
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_array);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
$page = curl_exec($ch);
echo $page;
No comments:
Post a Comment