doufuhuang6981 2016-11-04 15:33
浏览 78
已采纳

如何用PHP语言从HTML文件创建DOM对象?

I want to parsing data from homepage on this url. As you can see this url is HTML file and I read below:

// Create a DOM object from a HTML file
$html = file_get_html('test.htm');

so I just type a code below

include "simple_html_dom.php";
$html = file_get_html('eecs.kookmin.ac.kr/site/computer/notice.htm');
echo $html->plaintext;

The error message is:

Error message Warning: file_get_contents(eecs.kookmin.ac.kr/site/computer/notice.ht‌​m): failed to open stream: No such file or directory in C:\Bitnami\wampstack-5.6.27-0\apache2\htdocs\simple_html_dom‌​.php on line 76

what should I do?

  • 写回答

1条回答 默认 最新

  • doupuxuan5784 2016-11-04 16:49
    关注

    You can get the HTML code using the Snoopy Class (https://sourceforge.net/projects/snoopy). Next code displays the HTML code inside of a <textarea> tag, then it displays the page itself, copy-paste next code in a PHP file and open it in your browser:

    <!DOCTYPE html>
    <html>
      <head>
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=euc-kr">
        <META HTTP-EQUIV="Content-language" CONTENT="ko">
      </head>
      <body>
    <?php
    require("Snoopy.class.php"); // ◄■■ GET SNOOPY FROM https://sourceforge.net/projects/snoopy
    $snoopy = new Snoopy;
    $snoopy->fetch("http://eecs.kookmin.ac.kr/site/computer/notice.htm");
    $html = mb_convert_encoding( $snoopy->results, "UTF-8", "EUC-KR" ); // ◄■■ GET HTML CODE.
    echo "<textarea rows='25' cols='80'>$html</textarea>"; // ◄■■ DISPLAY THE HTML.
    echo $html; // ◄■■ DISPLAY THE WEBPAGE.
    ?>
      </body>
    </html>
    

    The Snoopy Class is only one file, make sure the file is in the same directory your PHP file is.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题