Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-FanLinks
- {
- Param
- (
- [int]$StartPage = 1,
- [int]$EndPage,
- [parameter(mandatory=$true,HelpMessage="Url to show you wish to parse ex. 'https://archiveofourown.org/tags/Assassin's%20Creed%20-%20All%20Media%20Types/works'")]
- [string]$url,
- [switch]$ExportCsv
- )
- $PostUri = 'https://archiveofourown.org'
- $UrlList = New-Object -TypeName System.Collections.Generic.List[PsObject]
- do
- {
- $SearchRootUri = "$($url)?page=$StartPage"
- try
- {
- $WebPage = Invoke-WebRequest -Uri $SearchRootUri
- }
- catch
- {
- Write-Host -ForegroundColor Red "$SearchRootUri is not a valid webpage"
- Write-Host -ForegroundColor Red " is not a valid webpage"
- break;
- }
- $links = $null
- $links = $WebPage.Links |
- where {$_.href -match '\d{1,}$' -and
- ($_.href.ToCharArray() | where {$_ -eq '/'}).count -eq 2} |
- select outerText,href -Unique
- foreach ($link in $links)
- {
- $hash = @{
- 'Page' = $StartPage
- 'WebPage' = $SearchRootUri
- 'Titel' = $link.outerText
- 'Url' = "$PostUri$($link.href)"
- }
- $obj = New-Object -TypeName PsObject -Property $hash
- $UrlList.Add($obj)
- }
- $StartPage++
- } until($links -eq $null -or $StartPage -eq $EndPage)
- if ($ExportCsv)
- {
- $UrlList | Export-Csv -Path "$env:USERPROFILE\desktop\Links.csv" -Delimiter ';' -Encoding Default -NoTypeInformation -Force
- }
- return $UrlList
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement