【问题标题】:Getting Specific Tag from Remote Site using PHP [duplicate]使用 PHP 从远程站点获取特定标签 [重复]
【发布时间】:2014-01-04 21:36:40
【问题描述】:
<?php
  $html = file_get_contents('http://xpool.xram.co/index.cgi');
  echo $html;
?>

我想使用 php 在远程网站的标签中获取信息。并且只有标签。

我发现这个小字符串非常适合检索整个网站源。但是,我只想得到一小部分。如何过滤掉所有其他标签,只获取我需要的一个标签?

【问题讨论】:

标签: php html html-parsing


【解决方案1】:

我建议使用 PHP DOM 解析器。 (http://simplehtmldom.sourceforge.net/manual.htm)

require_once ('simple_html_dom.php');

$html = file_get_contents('http://xpool.xram.co/index.cgi');

$p = $html->find('p'); // Find all p tags.

$specific_class = $html->find('.classname'); // Find elements with classname as class.

$element_id = $html->find('#element'); // Find element with the id element

阅读文档,还有很多其他可用选项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 2015-09-15
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多