Skip to content

Instantly share code, notes, and snippets.

@shivamMg
Created June 14, 2014 18:21
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 shivamMg/16a7440c9120df0bfa6e to your computer and use it in GitHub Desktop.
Save shivamMg/16a7440c9120df0bfa6e to your computer and use it in GitHub Desktop.
use URL (get method) to extract info
<?php
// create database 'db' and a table 'students' with cols INT 'id' and VARCHAR(2500) 'info'
$begin_id = 42332; // first id
$end_id = 45408; // last id
// 42332 to 45408 are ids of my college students 2nd yr to final yr
// mysql database info
$server="localhost";
$username="user";
$password="password";
$database="db";
$table="students";
// end mysqlinfo
$con=mysql_connect($server,$username,$password);
if(!$con)
{ echo "could not connect to db";exit(); }
mysql_select_db($database,$con);
$i = $begin_id;
while ( $i <= $end_id )
{
$filename="http://14.102.11.90/newregi/rcard.asp?USER=".$i."&YEAR=2013-2014&SEM=II"; // webpage address is filename
$webpage = file_get_contents( $filename,true );
$start = strpos($webpage,"<hR>"); // from first <hr>
$end = strpos($webpage,"<hR>",$start+1); // to second <hr>
$content = substr($webpage,$start,$end-$start); // take out the main-personal table (main-content)
$content = trim($content);
$content = addslashes($content);
// mysql save in a db
$sql = "INSERT INTO ".$table." (id,content) VALUES (".$i.",'".$content."');";
if( !empty($content))
{ mysql_query($sql,$con); }
echo "<br>done till : ".$i;
$i=$i+1;
}
mysql_close($con);
echo "done : from ".$begin_id." to ".$end_id;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment