【问题标题】:Funny 500 error when accessing page from php script从 php 脚本访问页面时出现有趣的 500 错误
【发布时间】:2012-04-15 21:02:50
【问题描述】:

我想解析不需要身份验证的http://gmmobile.atm-mi.it/wsbw/InfoTraffico/ 页面。然而,当我尝试通过 PHP 脚本访问它以解析其内容时,我收到一个错误:

警告:file_get_contents(http://gmmobile.atm-mi.it/wsbw/InfoTraffico/) [function.file-get-contents]:打开流失败:HTTP 请求失败!第 70 行 /iPhone/simplehtmldom_1_5/simple_html_dom.php 中的 HTTP/1.1 500 内部服务器错误

我使用的代码如下:

include('simple_html_dom.php');
// Create DOM from URL or file
$url='http://gmmobile.atm-mi.it/wsbw/InfoTraffico/';
echo $url;
$html = file_get_html($url);
echo $html;
$i=0;
foreach($html->find('option') as $content) 
{
    $linea=$content->value;
    $destination=$content->title;
        $i++;

}

可能是什么问题,我该如何解决?

【问题讨论】:

    标签: php html html-parsing simple-html-dom


    【解决方案1】:

    尝试添加一个用户代理:

    $url = 'http://gmmobile.atm-mi.it/wsbw/InfoTraffico/';
    $options = array('http' => array('header' => "User-Agent: myFooAgent\r\n"));
    $context = stream_context_create($options);
    echo file_get_contents($url, false, $context);
    

    【讨论】:

    • 谢谢,我会看看建议。
    • 非常感谢和抱歉没有及时实施,但我不得不解决其他问题,发现我想要实施的应用程序已经完成。
    • 你应该关闭这个问题。
    • 非常合理的建议,但是我该怎么做呢?
    猜你喜欢
    • 2017-02-03
    • 2011-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多