我如何使用简单的html dom php使用xml内的所有链接,并从他们得到我想要的标签


How i can use simple html dom php to use all the links inside xml and get the tags I want from them

我想一次从多个页面(不是SINGLE!)获得标签,并按其元素存储它们然后打印出来。

我能够解析xml文件并从中获得所有链接,但单独添加多个链接看起来要做很多工作。

我正试图从某个网站使用它的XML文件,已经有所有的链接建立标题IMG价格的数据。

一切帮助将不胜感激。

我使用以下代码获取所有链接:

<?php 
$urls = array(); 
$DomDocument = new DOMDocument(); 
$DomDocument->preserveWhiteSpace = false; $DomDocument->load('ivory.co.il/sitemap.xml'); 
$DomNodeList = $DomDocument->getElementsByTagName('loc'); 
foreach($DomNodeList as $url) { 
$urls[] = $url->nodeValue; 
} 
?>

我真的不知道你想做什么,但我会尽力帮助你。这是一个非常简单的解决方案,只需遵循以下步骤:

    从sourreforge下载PHP simple HTML DOM Parser .
  1. 用foreach循环遍历URL数组
  2. 在每个URL上找到你想要抓取的内容

这很难帮助你,因为我不知道你想从每个URL得到什么内容。但是看看我的例子,它会从SO的不同问题中抓取数据。

<?php
include 'simple_html_dom.php';
$list   = array("http://stackoverflow.com/questions/31993435/how-i-can-use-simple-html-dom-php-to-use-all-the-links-inside-xml-and-get-the-ta",
                "http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php?rq=1");
foreach($list as $url) {
    $html   = file_get_html($url);
    foreach($html->find('#content') as $content) {
        $row['url']     = $url;
        $row['title']   = $content->find('h1', 0)->plaintext;
        $row['vote']    = $content->find('span.vote-count-post', 0)->plaintext;
        $result[]       = $row;
    }
}
?>
<pre>
<?php print_r($result); ?>
</pre>

:

Array
(
    [0] => Array
        (
            [url] => http://stackoverflow.com/questions/31993435/how-i-can-use-simple-html-dom-php-to-use-all-the-links-inside-xml-and-get-the-ta
            [title] => How i can use simple html dom php to use all the links inside xml and get the tags I want from them
            [vote] => -2 
        )
    [1] => Array
        (
            [url] => http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php?rq=1
            [title] => How do you parse and process HTML/XML in PHP?
            [vote] => 1186 
        )
)