Last active
August 29, 2015 14:14
-
-
Save andre3k1/feb527b34774e00ffaa7 to your computer and use it in GitHub Desktop.
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 | |
include("lib/http.php"); | |
include("lib/parse.php"); | |
$product_array = array(); | |
$product_count = 0; | |
# Download the target web page | |
$target = "http://www.webbotsspidersscreenscrapers.com/buyair/"; | |
$ref = ""; | |
$web_page = http_get($target, $ref); | |
# Parse html tables to an array | |
$tables = parse_array($web_page['FILE'], "<table", "</table>"); | |
# Find the table containing products for sale | |
for ($i = 0; $i < count($tables); $i++) { | |
if (stristr($tables[$i], "Products For Sale")) { | |
# Parse the table rows to an array | |
$table_rows = parse_array($tables[$i], "<tr", "</tr>"); | |
# Find the row containing the table header | |
for ($row = 0; $row < count($table_rows); $row++) { | |
if (stristr($table_rows[$row], "Condition")) { | |
# Parse the cells in the header row to an array | |
$table_cells = parse_array($table_rows[$row], "<td", "</td>"); | |
# Find the column numbers for each data type | |
for ($col = 0; $col < count($table_cells); $col++) { | |
$cell = strip_tags(trim($table_cells[$col])); | |
if (stristr($cell, "ID#")) $id_column = $col; | |
if (stristr($cell, "Product name")) $name_column = $col; | |
if (stristr($cell, "Price")) $price_column = $col; | |
} | |
# Store the header row | |
$header_row = $row; | |
} | |
# Find the last row | |
if (stristr($table_rows[$row], "Calculate")) break; | |
# Parse product and price data | |
if (isset($header_row) && ($header_row < $row)) { | |
$table_cells = parse_array($table_rows[$row], "<td", "</td>"); | |
$product_array[$product_count]['ID'] = strip_tags(trim($table_cells[$id_column])); | |
$product_array[$product_count]['NAME'] = strip_tags(trim($table_cells[$name_column])); | |
$product_array[$product_count]['PRICE'] = strip_tags(trim($table_cells[$price_column])); | |
$product_count++; | |
} | |
} | |
} | |
} | |
# Display the collected data | |
for ($i = 0; $i < count($product_array); $i++) { | |
echo "$i. "; | |
echo "ID: ".$product_array[$i]['ID'].", "; | |
echo "NAME: ".$product_array[$i]['NAME'].", "; | |
echo "PRICE: ".$product_array[$i]['PRICE']."\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment