Advertisement
Combreal

scrapISBN.ps1

Mar 2nd, 2024 (edited)
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $CustomObjs=@()
  2.  
  3. $ISBN = "978-2-38275-162-6"
  4. $truncatedISBN = $ISBN -replace '-', ''
  5.  
  6. $booksHtml = Invoke-WebRequest "https://isbnsearch.org/isbn/$truncatedISBN"
  7. $bookInfo = $booksHtml.ParsedHtml.getElementsByClassName("bookinfo")[0].innerText
  8.  
  9. $cutBookInfo = $bookInfo.Split([System.Environment]::NewLine,[System.StringSplitOptions]::RemoveEmptyEntries)
  10.  
  11. $name = $cutBookInfo[0]
  12. $author = $cutBookInfo[3].Substring($cutBookInfo[3].IndexOf(": ") + 2)
  13. $binding = $cutBookInfo[4].Substring($cutBookInfo[4].IndexOf(": ") + 2)
  14. $publisher = $cutBookInfo[5].Substring($cutBookInfo[5].IndexOf(": ") + 2)
  15. $published = $cutBookInfo[6].Substring($cutBookInfo[6].IndexOf(": ") + 2)
  16. $coverLink = $booksHtml.Images[0].src
  17.  
  18. $CustomObj = New-Object -TypeName PSObject -Property @{ 'Name' = $name; 'ISBN' = $ISBN; "Author" = $author; "Binding" = $binding; "Publisher" = $publisher; "Published" = $published; "Cover" = $coverLink }
  19. $CustomObjs += $CustomObj
  20.  
  21. $CustomObjs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement