【问题标题】:Reading Another Website in PHP用 PHP 阅读另一个网站
【发布时间】:2016-12-03 00:13:08
【问题描述】:

我有一个 PHP 脚本,它创建一个日历并突出显示当前日期和所有内容。我想打开一个网站并阅读如下表,并获取“日期”的“信息”并将其放在我的日历上。

<table>
<tr>
<th>Date</th>
<th>Info</th>
</tr>
<tr>
<td>2/20/2013</td>
<td>Meeting</td>
</tr>
<tr>
<td>2/24/2013</td>
<td>Another meeting</td>
</tr>
</table>

使用此代码:

$url = $pageurl;
$content = file_get_contents($url);
$needle = $month . '/' . $list_day . '/' . $year;
if (strpos($content, $needle)) {
    $calendar .= '<p>STUFF</p><p>MORE STUFF</p>';
}

我已经取得了一定的成功,我现在可以将“STUFF”和“MORE STUFF”输出到日历上的某一天。但现在我想准确地发布那一天的内容。我怎样才能做到这一点?任何帮助将不胜感激。

【问题讨论】:

    标签: php html-table


    【解决方案1】:

    我回答了一个类似的问题here。您可以从那里复制getCellValue() 函数,然后像这样使用它:

    $dom = new DomDocument();
    $dom->preserveWhiteSpace = false;
    
    $dom->loadHtml('...table HTML here...');
    
    $table = $dom->getElementsByTagName('table')->item(0);
    
    print getCellValue($table, 'Info', array(
      'Date' => '2/20/2013',
    ));
    

    这应该打印请求日期(“会议”)的相应“信息”值

    【讨论】:

      【解决方案2】:

      您可能想要使用 DOM 解析器之类的东西。我在 Google 中寻找“DOM Parser PHP”,这是第一个链接:

      Library for DOM Parsing in PHP

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-06-18
        • 2016-09-14
        • 1970-01-01
        • 2016-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多