PHP file_get_contents / CURL不返回完整页面 [英] PHP file_get_contents / CURL not returning full page

查看:188
本文介绍了PHP file_get_contents / CURL不返回完整页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CURL或file_get_contents拉取第三方文件内容的一些奇怪的行为,页面的pasrt被读取,但它停止在随机位置...没有错误(超时等)。



可能最容易看到我是否给出了完整的例子:



使用以下的bsic脚本读取完整的URL并返回内容工作很好,与一个主题的一两秒的页面的全部内容(减少一些外部css等):

 <?php 
set_time_limit(180);
$ page = file_get_contents('http://www.fantasyleague.com/Classic/Stats/playerlist.aspx?dpt=3');
echo $ page;
?>

但是,如果我们更改为

 <?php 
set_time_limit(180);
$ page = file_get_contents('http://www.fantasyleague.com/Classic/Stats/playerlist.aspx?dpt=4');
echo $ page;
?>

它需要运行一段时间,最终返回页面的一部分,但不是全部。它不一致,但它通常以A Westwood AV 3.6 12或显示结束,在页面的上一点。



如果你看两个URL,你可以看到他们基本上prettu是一样的。这个行为刚刚开始出现,直到一天或两天前,都工作得很好。



任何想法?我可以提供任何进一步的信息,我错过了!



编辑:



finishes ...原始文件包含:

 < div class =right> 
< a id =Playerlist_help_buttonclass =button lefthref =#>< div>显示帮助< / div>< / a>
< a id =Playerlist_filters_buttonclass =button lefthref =#>< div>显示过滤器< / div>< / a>
< a class =button lefthref =PlayerListPrintable.aspxtarget =_ blank>< div>可打印版本< / div>< / a&
< br class =clear/>
< / div>

但检索到的数据停止在:

 < div class =right> 
< a id =Playerlist_help_buttonclass =button lefthref =#>< div>显示帮助< / div>< / a>
< a id =Playerlist_filters_buttonclass =button lefthref =#>< div>显示

或其他经常失败的地方是:

 < td>< div class =chilli normal/>< / td> 


< td> 12< / td>


< td> 0< / td>

即成为:

 < td>< div class =chilli normal/>< / td> 


< td> 12< / td>


解决方案

by file_get_contents或curl一次只能html源但不是所有组件


I'm geting some strange behaviour trying to pull 3rd party file contents using CURL or file_get_contents, pasrt of the page is read, but it stops at a random position... no error though (timeout etc).

Probably easiest to see if I give the full example!:

Using the following very bsic script to read a full URL and return the contents works just fine, with the full content of the page (less some external css etc) in a mater of a second or two:

<?php    
set_time_limit(180);
$page = file_get_contents('http://www.fantasyleague.com/Classic/Stats/playerlist.aspx?dpt=3');
echo $page;
?>

However, if we change to

<?php    
set_time_limit(180);
$page = file_get_contents('http://www.fantasyleague.com/Classic/Stats/playerlist.aspx?dpt=4');
echo $page;
?>

it takes ages to run, and eventually returns part of the page, but not all. It's not consistent, but it generally ends with either "A Westwood AV 3.6 12" or "show", a bit further up the page.

If you look at the two URLs, you can see they are basically prettu much the same. And this behaviour has onyl just started occuring, up until a day or two ago, both worked fine.

Any ideas? I can provide any further info I've missed out!

Edit:

An example of where the file finishes... original file contains:

<div class="right">
    <a id="Playerlist_help_button" class="button left" href="#"><div>Show help</div></a>
    <a id="Playerlist_filters_button" class="button left" href="#"><div>Show filters</div></a>
    <a class="button left" href="PlayerListPrintable.aspx" target="_blank"><div>Printable Version</div></a>
    <br class="clear" />
</div>

but the retrieved data stops at:

<div class="right">
    <a id="Playerlist_help_button" class="button left" href="#"><div>Show help</div></a>
    <a id="Playerlist_filters_button" class="button left" href="#"><div>Show 

or the other place it often fails is:

        <td><div class="chilli normal" /></td>


        <td>12</td>


        <td>0</td>

which becomes:

        <td><div class="chilli normal" /></td>


        <td>12</td>

解决方案

by file_get_contents or curl At one time only you can get html source but not all components

这篇关于PHP file_get_contents / CURL不返回完整页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆