-
-
Save Yogeshkad/5719c19b3d4d57a3c2be59b5d2f49b78 to your computer and use it in GitHub Desktop.
Grabbing a site in C# using phantomJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var page = require('webpage').create(), | |
system = require('system'); | |
page.onLoadFinished = function() { | |
console.log(page.content); | |
phantom.exit(); | |
}; | |
page.open(system.args[1]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = Config.PhantomJSPath, | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment