Javascript 简单HTML dom中的损坏图像
我正在使用simple_html_dom.php库从www.lifehacker.com等页面获取所需元素,但当我获取图像时,一些图像不会出现,它们的链接看起来断了。这是我正在使用的代码Javascript 简单HTML dom中的损坏图像,javascript,php,jquery,html,simple-html-dom,Javascript,Php,Jquery,Html,Simple Html Dom,我正在使用simple_html_dom.php库从www.lifehacker.com等页面获取所需元素,但当我获取图像时,一些图像不会出现,它们的链接看起来断了。这是我正在使用的代码 <html> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
$(document).ready(function(){
$("h1").click(function(){
$(this).hide();
});
});
$(document).ready(function(){
$("a").click(function(){
$(this).hide();
});
});
$(document).ready(function(){
$("img").click(function(){
$(this).hide();
});
});
$(document).ready(function(){
$("href").click(function(){
$(this).hide();
});
});
</script>
<style type="text/css">
br{
display: none;
}
</style>
</head>
<body style="margin: 0 auto;max-width:900px; border:1px solid; padding:20px; margin-top:20px; ">
<?php
include_once('simple_html_dom.php');
$html = file_get_html('http://www.lifehacker.com/');
foreach($html->find('.icon') as $item) {
$item->outertext = '';
}
$html->save();
foreach($html->find('br') as $item) {
$item->outertext = '';
}
$html->save();
$title = $html->find('title',0)->innertext;
$title = '<h1>'.$title.'<h1>';
echo $title;
$html=$html->find('h1 , h2 , h3 ,img, p');
foreach($html as $elements){
foreach($elements->find('a') as $element) {
if (isset($element->href)) {
$element->href = null;
}
}
foreach($elements->find('br') as $element){
if(isset($element->br)){
$element->br=null;
}
}
echo $elements.'<br>';
}
?>
</body>
</html>
这是断开的URL的图像
它们是相对url吗?如果是这样,您需要将它们转换为绝对的oneshow。这是可能的吗?检查协议和域是否在图像url字符串中,如果不将它们添加到字符串中,请给出如何添加url的提示?在php中使用字符串比较方法检查url值