强制javascript生成的内容显示自己

I'm generating some content through an API, accessed by javascript, and I cannot grab the source code of what is plainly displayed, post-load, on the browser. I can highlight the text and view the source of selected text (which is a firefox feature), but I will be using CURL to capture the data automatically with php... How can I capture the data? Is there a way to update the source(maybe through a DOM update) so it displays some how? Any help is appreciated.

You can't just request some HTML source and expect the results of modifying it with JS to be in place without running the JS so if you want to get the content in PHP, then you will have to either

  1. Push the HTML through something that will execute the JavaScript (I'd probably look to WWW::Mechanize::Firefox if I were using Perl, it uses Mozrepl. I don't know if PHP has a similar nice API for it)
  2. Reverse engineer the JavaScript and do whatever it does to get the data yourself.

You can pull up the page source using Google Chrome from within developer tools (wrench in the top right -> Tools -> Developer tools, or Control+Shift+I (that's an uppercase i)). The source code shown in the developer tools represents the up-to-date source code of the page, including things that were generated dynamically by JavaScript after the page initially loads.

I'm sure other browsers have similar capabilities, I just happen to know Chrome's method off the top of my head.

If you developing environment is Linux/Unix, you could incorporate PjantonJS, which is a very nifty tool that executes the JavaScript and it passes the output. The way I would recommend doing this would be with a shell_exec() in witch you run you CLI PhantomJS.

Hope this helps.