Created
January 14, 2011 14:57
-
-
Save StevenMcD/779698 to your computer and use it in GitHub Desktop.
scrape table results from page
This file contains hidden or 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
cls | |
$comics = @() | |
foreach($number in 1..25){ | |
$page = (new-object System.Net.Webclient).DownloadString("http://www.awx.co.za/e107_plugins/shop/show_cat.php?lettersort=B&catpath=64/Comics&page=$number") | |
$startIndex = $page.IndexOf("main_section") | |
$startIndex = $page.IndexOf("main_section",$startIndex + 20) | |
$endIndex = $page.IndexOf("</table>",$startIndex) | |
$table = $page.substring($startIndex, $endIndex - $startIndex) | |
$columns = $table -split "<tr>" | |
$columns | % { | |
$columnDetails = $_ -split "<td " | |
if($columnDetails.length -gt 1){ | |
$titleIndex = $columnDetails[2].indexof("title=") + "title=".length | |
$titleEndIndex = $columnDetails[2].indexof(">",$titleIndex) | |
#Write out the items name | |
$comicName = $columnDetails[2].substring($titleIndex, $titleEndIndex - $titleIndex).replace("`"","") | |
if($columnDetails[2].indexof("green") -gt -1 ){ | |
$comicAvailable = "In Stock" | |
}else{ | |
$comicAvailable = "out Of Stock" | |
} | |
#Write out the items price | |
$comicPrice = $columnDetails[3].substring($columnDetails[3].indexof(">")+1).replace("</td>","") | |
$comic = New-Object System.Object | |
$comic | Add-Member -type NoteProperty -name Name -value $comicName | |
$comic | Add-Member -type NoteProperty -name Price -value $comicPrice | |
$comic | Add-Member -type NoteProperty -name Available -value $comicAvailable | |
$comics += $comic | |
} | |
} | |
} | |
$comics |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment