PHP file_get_contents / CURL not returning full page

╄→尐↘猪︶ㄣ 提交于 2019-12-10 17:22:11

问题


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>

回答1:


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



来源:https://stackoverflow.com/questions/14123378/php-file-get-contents-curl-not-returning-full-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!