Stas_P

Phantomjs scraping + utf8 output

Feb 9th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $scrapingUrl="http://asite.com"
  2.  
  3. $fullPathIncFileName = $MyInvocation.MyCommand.Definition
  4. $currentScriptName = $MyInvocation.MyCommand.Name
  5. $currentExecutingPath = $fullPathIncFileName.Replace($currentScriptName, "")
  6. $jsPath = $currentExecutingPath + "js/scraping.js"
  7. $si = New-Object -TypeName System.Diagnostics.ProcessStartInfo
  8. $si.FileName = "D:\Distrib\phantomjs\phantomjs.exe"
  9. $si.Arguments = "--proxy-type=none --load-images=no $jsPath $scrapingUrl"
  10. $si.StandardOutputEncoding = [System.Text.Encoding]::UTF8
  11. $si.RedirectStandardOutput = $TRUE
  12. $si.UseShellExecute = $FALSE
  13. $si.CreateNoWindow = $TRUE
  14.  
  15. $process = [System.Diagnostics.Process]::Start($si)
  16.  
  17. $started = $FALSE;
  18. while (-not $process.StandardOutput.EndOfStream)
  19. {
  20.     Start-Sleep 1
  21.     $process.Refresh();
  22.     $line =  $process.StandardOutput.ReadLine()
  23.     if($started){
  24.         $Output = $Output + $line
  25.     }
  26.     if($line -eq ">>>>>>>data>>>>>>>"){ #data marker
  27.         $started = $TRUE
  28.     }
  29. }
  30. $Output|Out-File "result.txt"
  31. Write-Host $Output
Advertisement
Add Comment
Please, Sign In to add comment