如何使用 html DOM 重新创建图像 src 链接


How to recreate a image src link using html DOM?

我使用 HTML DOM 抓取其他页面内容,当我抓取一些图像时,它是 src 的显示,如下所示 -

<img src="/datas/vt/data=Ay5GWBeob_WIPLDYoIWcfVXxvZu9XwJ55OX7Ag,OfrBKR" style="margin-right: 12px; margin-top: 1px; padding: 1px;" width="270" border="1" height="185">

有没有办法将内容添加到图像源中? 示例:www.contentgrabbingsitename.com !!!

喜欢

<img src="www.contentgrabbingsitename.com/datas/vt/data=Ay5GWBeob_WIPLDYoIWcfVXxvZu9XwJ55OX7Ag,OfrBKR" style="margin-right: 12px; margin-top: 1px; padding: 1px;" width="270" border="1" height="185">

我的代码:

foreach($html->find('img') as $e)
    echo $e->outertext . '<br>';

您可以编辑属性,例如:

foreach($html->find('img') as $e) {
    // prefix 'hello' to the src attribute
    if ('/' == $e->src[0]) {
        $e->src = "http://mydomain.com" . $e->src;
    }
}

之后,您只需保存页面即可。