【问题标题】:can't get html from webpage无法从网页获取 html
【发布时间】:2015-06-01 03:14:51
【问题描述】:

file_get_htm 返回 false,但如果我尝试将数据转换为字符串,那么一切正常 ..

$url = "http://www.dkb-handball-bundesliga.de/de/dkb-hbl/spielplan/spielplan-chronologisch/";

$output = file_get_contents($url);
print_r($output); //this return string 

$html = file_get_html($url);
print_r($html); //this return false

我尝试使用 curl,但一切都一样......

例如,如果我使用 cgange url,一切正常...

$url='http://www.dkb-handball-bundesliga.de/de/s/spiele/2014-2015/dkb-handball-bundesliga/1--spieltag--bergischer-hc-vs-sg-bbm-bietigheim/';

【问题讨论】:

  • 如果这适用于一个页面而不适用于另一个页面,则您正在检索的 HTML 可能已损坏。

标签: php file-get-contents simple-html-dom


【解决方案1】:

您将从这里获取数据:

    <?php
    // put your code here
        include_once './simple_html_dom.php';
        $html = file_get_html("http://www.dkb-handball-bundesliga.de/");   
        $links = array();
        foreach($html->find('a') as $a) {
            $links[] = $a->href;
        }
        print_r($links);
    ?>

<html>
<head>
    <title>TODO supply a title</title>
    <meta charset="ISO-8859-1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    <div>TODO write content</div>
    <table>
        <tr>
            <th>My elements</th> 
            <a href="/hello1">Hello world 1</a>
            <a href="/hello2">Hello world 2</a>
            <a href="/hello3">Hello world 3</a>
            <a href="/hello4">Hello world 4</a>
            <a href="/hello5">Hello world 5</a>
        </tr>
    </table>
</body>
</html>



    <?php
       // You need to know the location of the file that you are calling.
        include_once './simple_html_dom.php';
        $html = file_get_html("http://localhost/PhpHelpers/examples.html");   
        $links = array();
        foreach($html->find('a') as $key => $val) {
            $links[$key] = $val; 
        }
        print_r($links);
    ?>

【讨论】:

  • 是的,我在这里发帖时出错...我使用了单引号,但没有帮助
  • 也许这篇文章对你有帮助:stackoverflow.com/questions/22080731/…
  • 你包括图书馆吗?包括('simple_html_dom.php'); $html = file_get_html("google.com"); var_dump($html);
  • 尝试其他网站。并打印结果。
  • 当然我包含库...如果没有,那么当我更改 url 时脚本不起作用...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-30
  • 2019-01-05
  • 2023-04-03
  • 2016-09-17
  • 2016-09-15
  • 1970-01-01
相关资源
最近更新 更多