Skip to content

Instantly share code, notes, and snippets.

@cakriwut
Created October 5, 2016 15:19
Show Gist options
  • Save cakriwut/37ed75512cf56214ef785daee3b10638 to your computer and use it in GitHub Desktop.
Save cakriwut/37ed75512cf56214ef785daee3b10638 to your computer and use it in GitHub Desktop.
How to download URL news link from www.detik.com
# Defines date range of the news
$startDate = Get-Date "2016-01-01"
$endDate = Get-Date
# Defines file capture location
$fileCapture = "C:\temp\detik.txt"
$detikApi = "http://apis.detik.com/v1/indeks?limit=500&channelid=10&gt={0:yyyy-MM-dd HH:mm:ss}&lt={1:yyyy-MM-dd HH:mm:ss}"
$currentDate = $startDate
do {
$nextDate = $currentDate.AddMonths(1)
# Format URL api
$uri = $detikApi -f $currentDate , $nextDate
# Shift to next day
$currentDate = $nextDate
$x = Invoke-WebRequest -Uri $uri -ContentType "application/json" | ConvertFrom-Json
$x.data | select -ExpandProperty Url | Add-Content $fileCapture
} while($currentDate -lt $endDate)
@cakriwut
Copy link
Author

cakriwut commented Oct 5, 2016

ChannelId is valid from 1 - 12
This method is preferable compared to Detik.com's RSS feed. The RSS feeds only allow retrieval of 50 latest feed, without possibility to request more or request different date range.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment