Skip to content

Instantly share code, notes, and snippets.

@CelestialMusa
Forked from DotNetNerd/PhantomRunner.cs
Created August 3, 2016 22:35
Show Gist options
  • Save CelestialMusa/9d2142a7f68180b5426823264c40693f to your computer and use it in GitHub Desktop.
Save CelestialMusa/9d2142a7f68180b5426823264c40693f to your computer and use it in GitHub Desktop.

Revisions

  1. @DotNetNerd DotNetNerd revised this gist May 23, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion PhantomRunner.cs
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ public string Grab(string url)
    WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
    UseShellExecute = false,
    RedirectStandardOutput = true,
    FileName = "C:\\Users\\chn\\Desktop\\phantomjs-1.9.0-windows\\phantomjs",
    FileName = Config.PhantomJSPath,
    Arguments = string.Format("\"{0}\\{1}\" {2}", Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "index.js", url)
    };

  2. @DotNetNerd DotNetNerd created this gist May 23, 2013.
    34 changes: 34 additions & 0 deletions PhantomRunner.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    class Program
    {
    static void Main(string[] args)
    {
    var grabby = new Grabby();

    string output = grabby.Grab("http://www.dotnetnerd.dk/cv");
    Console.WriteLine(output);
    File.WriteAllText("c:\\test.html", output);
    }
    }

    public class Grabby
    {
    public string Grab(string url)
    {
    var process = new System.Diagnostics.Process();
    var startInfo = new System.Diagnostics.ProcessStartInfo
    {
    WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
    UseShellExecute = false,
    RedirectStandardOutput = true,
    FileName = "C:\\Users\\chn\\Desktop\\phantomjs-1.9.0-windows\\phantomjs",
    Arguments = string.Format("\"{0}\\{1}\" {2}", Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "index.js", url)
    };

    process.StartInfo = startInfo;
    process.Start();
    string output = process.StandardOutput.ReadToEnd();
    process.WaitForExit();

    return output;
    }
    }
    9 changes: 9 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    var page = require('webpage').create(),
    system = require('system');

    page.onLoadFinished = function() {
    console.log(page.content);
    phantom.exit();
    };
    page.open(system.args[1]);