Advertisement
Guest User

Untitled

a guest
May 5th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. var casper = require('casper').create({
  2. waitTimeout: 120000,
  3. stepTimeout: 120000,
  4. verbose: true,
  5. logLevel: "debug"
  6. });
  7.  
  8. require('CasperX');
  9. var process = require("child_process")
  10. var spawn = process.spawn
  11.  
  12. casper.start('http://baidu.com')
  13.  
  14. casper.then(function () {
  15. var exit = false;
  16. casper.echo(httpCall('baidu.com', 'GET', null, null))
  17. })
  18.  
  19. function httpCall(url, method, body, headers) {
  20. var para = ["-X", method]
  21. for (var prop in headers) {
  22. para.push("--header")
  23. para.push(para + ": " + headers[prop])
  24. }
  25. if (body) {
  26. para.push("-d")
  27. para.push(body)
  28. }
  29. para.push(url);
  30. casper.log('curl with parameters: ' + para)
  31. var child = spawn("curl", para)
  32. var result = "abc"
  33. child.stdout.on("data", function (data) {
  34. casper.echo("curl ended.")
  35. result = data;
  36. })
  37. return result;
  38. }
  39.  
  40. casper.then(function () {
  41. casper.wait(2000)
  42. })
  43. casper.run()
  44.  
  45. [info] [phantom] [2016-05-05T10:23:36.196Z] Starting...
  46. [info] [phantom] [2016-05-05T10:23:36.203Z] Running suite: 4 steps
  47. [debug] [phantom] [2016-05-05T10:23:36.226Z] opening url: http://baidu.com/, HTTP GET
  48. [debug] [phantom] [2016-05-05T10:23:36.227Z] Navigation requested: url=http://baidu.com/, type=Other, willNavigate=true, isMainFrame=true
  49. [debug] [phantom] [2016-05-05T10:23:36.461Z] Navigation requested: url=https://www.baidu.com/, type=Other, willNavigate=true, isMainFrame=true
  50. [debug] [phantom] [2016-05-05T10:23:36.684Z] url changed to "https://www.baidu.com/"
  51. [debug] [phantom] [2016-05-05T10:23:37.364Z] Successfully injected Casper client-side utilities
  52. [debug] [phantom] [2016-05-05T10:23:37.382Z] start page is loaded
  53. [info] [phantom] [2016-05-05T10:23:37.406Z] Step anonymous 3/4 https://www.baidu.com/ (HTTP 200)
  54. [debug] [phantom] [2016-05-05T10:23:37.406Z] curl with parameters: -X,GET,baidu.com
  55. abc <- I want it to be the stdout of curl...
  56. [info] [phantom] [2016-05-05T10:23:37.413Z] Step anonymous 3/4: done in 1216ms.
  57. [info] [phantom] [2016-05-05T10:23:37.429Z] Step anonymous 4/4 https://www.baidu.com/ (HTTP 200)
  58. [info] [phantom] [2016-05-05T10:23:37.430Z] Step anonymous 4/4: done in 1233ms.
  59. [info] [phantom] [2016-05-05T10:23:37.451Z] Step _step 5/5 https://www.baidu.com/ (HTTP 200)
  60. [info] [phantom] [2016-05-05T10:23:37.451Z] Step _step 5/5: done in 1254ms.
  61. curl ended.
  62. [info] [phantom] [2016-05-05T10:23:39.452Z] wait() finished waiting for 2000ms.
  63. [info] [phantom] [2016-05-05T10:23:39.453Z] Done 5 steps in 3256ms
  64. [debug] [phantom] [2016-05-05T10:23:39.455Z] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true
  65. [debug] [phantom] [2016-05-05T10:23:39.456Z] url changed to "about:blank"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement