Skip to content

Instantly share code, notes, and snippets.

@mikemorris
Created May 1, 2012 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikemorris/2569571 to your computer and use it in GitHub Desktop.
Save mikemorris/2569571 to your computer and use it in GitHub Desktop.
PHP Script to scrape records from corp.dcra.dc.gov
<?php
function dcra($username, $password, $search) {
$tmp_fname = tempnam('/tmp', 'COOKIE');
$curl_handle = curl_init ('https://corp.dcra.dc.gov/Account.aspx/LogOn');
curl_setopt($curl_handle, CURLOPT_COOKIEJAR, $tmp_fname);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, true);
$login_fields = array(
'username'=>$username,
'password'=>$password,
'LogOn'=>'Log On'
);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $login_fields);
$login_output = curl_exec($curl_handle);
file_put_contents('login.html', $login_output);
$curl_handle = curl_init ('https://corp.dcra.dc.gov/Home.aspx/ProcessRequest');
curl_setopt($curl_handle, CURLOPT_COOKIEFILE, $tmp_fname);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, true);
$fields = array(
'BizEntitySearch_String'=>$search,
'Search'=>'Search',
'BizEntitySearch_Type'=>'FileNumber',
'BizEntitySearch_DepthType'=>'Contains',
'BizEntitySearch_EntityStatus'=>'',
'BizEntitySearch_TradeNameStatus'=>''
);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $fields);
$output = curl_exec($curl_handle);
file_put_contents('dcra.html', $output);
}
echo 'Enter username:';
$stdin = fopen('php://stdin', 'r');
$username = trim(fgets($stdin));
echo 'Enter password:';
$stdin = fopen('php://stdin', 'r');
$password = trim(fgets($stdin));
echo 'Enter search string:';
$stdin = fopen('php://stdin', 'r');
$search = trim(fgets($stdin));
if ($username && $password && $search) {
dcra($username, $password, $search);
} else {
echo 'Invalid username, password or search query.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment