-
-
Save thirtythreeforty/4402737a745e8209ed08ae80f4f8dc60 to your computer and use it in GitHub Desktop.
Uses powershell to scrape website content for coupon sites using their json api's.
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
# this grabs offers from stater bros.com | |
$coupons = $null | |
$json = Invoke-WebRequest -Uri "http://coupons.staterbros.com/Coupons/Index?pageSize=600¤tPage=1&filter=0&sort=1&couponType=4&brandName=AllBrands&_=1383513834477" | select-object -Property Content | |
$StaterBriosrawObj = ConvertFrom-Json $json.Content | |
$StaterBriosrawObj.CouponsGrid | Group-Object { $_.Name } | Sort-Object -Descending Count | |
$staterCoupons = $StaterBriosrawObj.CouponsGrid | |
$coupons += $staterCoupons | Select-Object @{Name="Brand"; Expression={ $_.Name.tolower() -replace "[^A-Za-z0-9_.\$@ ]","" }}, #-replace [char]174, '' -replace [char]8482, '' } }, | |
@{Name="Category";Expression={ "N/A"}}, | |
@{Name="Discount"; Expression={$_.Discount}}, | |
@{Name="Expiration"; Expression="ExpirationDate"}, | |
@{Name="Description"; Expression={$_.Details -replace "[^A-Za-z0-9_.\$@ ]","" }},#-replace [char]174,'' -replace [char]8482, '' -replace [char]162, "\u162" -replace [char]180, '\u180' -replace [char]96, '\u096' -replace[char]0x65, '' -replace [char]0x73, ''}}, | |
@{Name="Provider"; Expression={"staters"}} | |
#get data from ralphs | |
$ie = new-object -com "InternetExplorer.Application" | |
$ie.navigate("http://kroger.softcoin.com/programs/kroger/digital_coupons/?campaign=DigitalCoupons&banner=Ralphs") | |
$ie.Visible = $true | |
#$ie.navigate("http://kroger.softcoin.com/programs/kroger/digital_coupons/?campaign=DigitalCoupons&banner=Food4Less") | |
$ie.Document.cookie | |
$ie.visible = $true # Need this for a hack in IE | |
$ie.Quit() | |
$NewAuthCookie = New-Object System.Net.Cookie | |
$NewAuthCookie.Name = "JSESSIONID" | |
$NewAuthCookie.Path = "/" | |
$NewAuthCookie.Domain = "kroger.softcoin.com" | |
$NewAuthCookie.HttpOnly = $false | |
$NewAuthCookie.Secure = $false | |
$NewAuthCookie.Value = $cookieData[4] | |
#$ralphsSession = '' | |
$domain = [System.Uri]'http://kroger.softcoin.com' | |
$session.Cookies[0].SetCookies($domain, $NewAuthCookie) | |
$ralphsJson = Invoke-WebRequest -Uri "http://kroger.softcoin.com/p/np/4230/Kroger/coupons?banner=Ralphs&usource=KWL" -WebSession $session | select-object -Property Content | |
$ralphsRawObj = ConvertFrom-Json $ralphsJson.Content | |
echo "Ralphs crap!" | |
#$ralphsRawObj.coupons[0] | |
#$ralphsRawObj.coupons | Group-Object { $_.category } | Sort-Object -Descending Count | |
$ralphsCoupons = $ralphsRawObj.coupons | |
$coupons += $ralphsCoupons | Select-Object @{Name="Brand"; Expression={$_.brand}}, | |
@{Name="Category"; Expression={$_.category}}, | |
@{Name="Discount"; Expression={$_.value}}, | |
@{Name="Expiration"; Expression="expiration_date"}, | |
@{Name="Description"; Expression={$_.long_description -replace [char]174,'' -replace [char]8482, '' -replace [char]162, "\u162" -replace [char]180, '\u180' -replace [char]96, '\u096' -replace[char]0x65, '' -replace [char]0x73, ''}}, | |
@{Name="Provider"; Expression={"ralphs"}} | |
"Coupons in Set " + $coupons.Count | |
#MAP THIS! | |
foreach ($coupon in $coupons){ | |
$scriptInstance = ConvertTo-Json -InputObject $coupon | |
Invoke-RestMethod -Method Post -Uri "http://localhost:9200/coupons/coupon" -Body $scriptInstance | |
} | |
$coupons.Count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment