Created
May 1, 2012 16:50
-
-
Save mikemorris/2569571 to your computer and use it in GitHub Desktop.
PHP Script to scrape records from corp.dcra.dc.gov
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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