Created
September 10, 2013 06:25
-
-
Save ProLoser/6505661 to your computer and use it in GitHub Desktop.
Bash.org scraper written in PHP
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 | |
$con = mysqli_connect("localhost","root","","password"); | |
if(isset($_GET['scan'])) { | |
for($i=$_GET['scan'];$i<$_GET['scan']+10;$i++){ | |
$string = file_get_contents('http://bash.org/?browse&p='.$i); | |
preg_match_all('/<p class="quote"><a href="\?(\d+)".*?>\((-?\d+)\)<.*?<p class="qt">(.*?)<\/p>/si',$string,$matches); | |
echo '<br>Page '.$i.':'; | |
for($j=0;$j<count($matches[0]);$j++){ | |
echo ' '.$j; | |
//echo "INSERT INTO bash (id, rank, contents) VALUES (".$matches[1][$j].",".$matches[2][$j].",'".ereg_replace('<br />','',$matches[3][$j])."')"; | |
mysqli_query($con,"INSERT INTO bash (id, created, rank, contents) VALUES (".$matches[1][$j].",NOW(),".$matches[2][$j].",'".ereg_replace('<br />','',$matches[3][$j])."')"); | |
} | |
} | |
}else{ | |
if(isset($_GET['d'])) | |
mysqli_query($con,"DELETE FROM `bash` WHERE `bash`.`id` =".$_GET['d']); | |
if (!isset($_GET['i'])) $_GET['i'] = 200; | |
$result = mysqli_query($con, "SELECT id, rank, contents FROM bash ORDER BY rank ASC LIMIT ".$_GET['i']); | |
$i=0; | |
while ($row = mysqli_fetch_assoc($result)) { | |
$i++; | |
echo '<p><a style="color:red" href="?d='.$row['id'].'">[X]</a> #'.$i.' ID ['.$row['id'].'] RANK ['.$row['rank'].']<br>'.preg_replace('/\n/','<br>',$row['contents']).'</p>'; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment