PHP后端发送Ajax情书,How to use file_get_contents on Ajax site

问题

When you use file_gets_contents($website) or cURL to load a website, does it load the whole website? I am mostly interested about using cURL.

I am using it to load a webpage that then gets some contents such as price using AJAX and it has some problems getting the prices.

When I use file_get_contents, does it load as normally as a whole website does on a browser plus the stuff loaded using Ajax?

回答1:

No. Using file_get_contents() will only return the page contents, it will not execute any JavaScript on the page itself. The analog of this behaviour is almost equivalent to "View Page Source" in a browser.

回答2:

The snippet

$website = 'http://stackoverflow.com/';

file_gets_contents($website)

loads the result of the HTTP-request, nothing else. Thus, the call loads the source of the html-page returned by the URL http://stackoverflow.com/.

Especially, file_gets_contents() does not load stuff referenced by the page pointed to by http://stackoverflow.com/.

Evaluating JavaScript code using PHP

In case you'd like to evaluate JavaScript inside of HTML-code using a PHP-script, you'd probably wish to use the V8 JavaScript engine, which needs to be compiled into your PHP-binary:

http://php.net/manual/en/book.v8js.php

Find an example how to use the V8 JavaScript engine here.

来源:https://stackoverflow.com/questions/13978016/how-to-use-file-get-contents-on-ajax-site

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值