Skip to content

Instantly share code, notes, and snippets.

@StevenMcD
Created January 14, 2011 14:57
Show Gist options
  • Save StevenMcD/779698 to your computer and use it in GitHub Desktop.
Save StevenMcD/779698 to your computer and use it in GitHub Desktop.
scrape table results from page
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