Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!
The newest one, of course There's no reason to run an old PowerShell.
EDIT: Misread 2008 vs 2005. Only 2.0 works on XP, but really, how much longer are companies going to hold on to XP?
I DIDN'T EVEN NOTICE... There is also Version 4.0.
Some of the things I read mention the 4.0 preview at least is not supported on Windows 8 (but didn't say whether that would apply to the final release), and would only work on 7 SP1+ and 8.1+. Odd choice, there.
# Just for fun, create a class to hold our item information. Not necessary, but I was playing around with custom types.. really easy to do in PS.
Add-Type @'
public class myItem
{
public double regPrice;
public double salePrice;
public string name;
public int sku;
public int discount;
public myItem(string n,int s,double rp,double sp)
{
regPrice = rp;
salePrice = sp;
name = n;
sku = s;
discount = (int)(100-(salePrice/regPrice*100));
}
public void print()
{
System.Console.WriteLine("Item Name:\t" + name);
System.Console.WriteLine("Sku Number:\t" + sku);
System.Console.WriteLine("Reg. Price:\t" + regPrice);
if(salePrice == 8675309)
{
System.Console.WriteLine("Sale Price:\tAdd to Cart");
System.Console.WriteLine("Discount:\tN/A");
}
else
{
System.Console.WriteLine("Sale Price:\t" + salePrice);
System.Console.WriteLine("Discount:\t%" + discount + " Off");
}
}
}
'@
# Empty array to hold the stores that we find with an item in stock
clear
$items= @()
# Your store number
$STORENUM=1438
$site = Invoke-WebRequest "http://www.bestbuy.com/site/olstemplatemapper.jsp?id=pcat17096&type=page&strId=$STORENUM&nrp=500&cp=1&sp=clearancePrice"
$content = $site.AllElements | Where Class -eq 'hproduct'
# Loop through each row in our table, each one contains store data (name, addr, zip, distance, stock, etc)
Foreach ($row in $content)
{
$html = $row.innerHTML.toLower()
$html >> scrape2.html
$nameStart = $html.indexOf('rel=product>')+12
$nameStop = $html.indexOf('</a> </h3>') - $nameStart
$salePriceStart = $html.indexOf('3836809_sale')+ 14
$regPriceStart = $html.indexOf('reg. price: ') + 12
$NAME = $html.Substring($nameStart,$nameStop)
$SALEPRICE = $html.SubString($salePriceStart,10).Trim("<span")
$REGPRICE= $html.SubString($regPriceStart,10).Trim("<span")
$SKU = $html.SubString($html.indexOf('class=sku>')+10,10).Trim("</strong")
if(!($REGPRICE -match '\$.*'))
{
$REGPRICE= $html.SubString($regPriceStart+20,10).Trim("</span")
}
if(!($SALEPRICE -match '\$.*'))
{
$SALEPRICE = "8675309" # A not-so-graceful way to handle when there isn't actually a price listed. :)
}
$SALEPRICE = $SALEPRICE.Trim("$")
$REGPRICE= $REGPRICE.Trim("$")
$DISCOUNT = [int](100-(($SALEPRICE/$REGPRICE)*100))
$items += New-Object myItem($NAME,$SKU,$REGPRICE,$SALEPRICE);
# Debug printing, not needed.
# echo "Item Name:`t$NAME"
# echo "Item SKU:`t$SKU"
# echo "Reg. Price:`t$REGPRICE"
# echo "Sale Price:`t$SALEPRICE"
# echo "Discount:`t%$DISCOUNT Off"
# echo "--------------------------------------------------"
}
# Print out our items where discount is > 60%, sort, etc.
$items | Where-object discount -gt 60 | sort-object discount -descending
# Filter in other ways
# foreach ($item in $items)
# {
# if (($item.discount -gt 75) -or ($item.regPrice -gt 200))
# {
# $item.print()
# echo "----------------------------------------------------"
# }
# }