用简单的HTML DOM修改url


Modifying URLs with Simple HTML DOM

我使用以下代码来抓取-代码工作并提取我想要的所有内容-并不复杂。

原始站点使用相对url,因此抓取的html不起作用。

我如何修改这一点,使我添加http://wales.gov.uk/到每个URL的前面?

(我不想使用,因为我很可能想在一个页面上合并多个刮痧)

我就是看不懂文件。

欢呼
<?php
// includes Simple HTML DOM Parser
include "simple_html_dom.php";
$html_code="http://wales.gov.uk/consultations/education/?status=open&lang=en";
// echo $html_code;
$html = file_get_html($html_code);

// Loop through all divs with class=.topic-item"
foreach($html->find('.topic-item') as $e){
echo $e->outertext . '<br>';
}

// Clear dom object
$html->clear(); 
unset($html);
?>

对于它的价值,输出是:http://h100g.org.uk/news/news4.html

像这样:

foreach($html->find('.topic-item') as $e){
    $e->href = 'http://wales.gov.uk/'.$e->href;
}