Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .Synopsis
- Short description
- .DESCRIPTION
- Long description
- .EXAMPLE
- Example of how to use this cmdlet
- .EXAMPLE
- Another example of how to use this cmdlet
- #>
- function Get-RedditComments
- {
- [CmdletBinding()]
- [Alias()]
- [OutputType([int])]
- Param
- (
- # Param1 help description
- [Parameter(Mandatory=$true,
- ValueFromPipelineByPropertyName=$true,
- Position=0)]
- [string]
- $Username
- )
- Begin
- {
- }
- Process
- {
- $CommentsHTML = Invoke-WebRequest -uri "https://www.reddit.com/user/$username"
- $Comments = $commentshtml.ParsedHtml.getElementsByTagName("Div") | ?{$_.ClassName -like " Thing *"}
- Foreach ($comment in $comments)
- {
- $commentarray = $comment.innertext.split("`n")
- Try
- {
- $title = $commentarray | select -first 1
- $body = $commentarray | select -last ($commentarray.count - 3) | select -first ($commentarray.count - 9)
- $day = (($comment.outerhtml).split(' ') | ? {$_ -like "*datetime*"}).split("`"")[1].split("T+")[0]
- $time = (($comment.outerhtml).split(' ') | ? {$_ -like "*datetime*"}).split("`"")[1].split("T+")[1]
- $offset = (($comment.outerhtml).split(' ') | ? {$_ -like "*datetime*"}).split("`"")[1].split("T+")[2]
- $date = get-date -month $day.split("-")[1] -day $day.split("-")[2] -year $day.split("-")[0] -hour $time.split(":")[0] -minute $time.split(":")[1] -Second $time.split(":")[2]
- $props = @{ ‘Username’=$username
- ‘Title’=$title
- ‘Comment’=$body
- 'Date'=$date
- }
- $obj = New-Object -TypeName PSObject -Property $props
- Write-Output $obj
- }
- Catch
- {
- }
- }
- }
- End
- {
- }
- }
Add Comment
Please, Sign In to add comment