我试图刮一个网页,但在我的浏览器控制台中得到了一些奇怪的结果(如下面所示)。这是我的密码:
index.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Icefilms Searcher</title>
<script type="text/javascript" src="jquery-2.0.3.min.js"></script>
</head>
<body>
<script type="text/javascript" src="script.js"></script>
<div id="container" style="width:1100px;position:relative;"></div>
</body>
</html>
script.js
$(document).ready(function(){
var currNum = 168000;
var maxNum = 168005;
function generateNextUrl(){
currNum++;
return currNum-1;
}
scrapeThis(generateNextUrl());
function scrapeThis(theUrl){
$.ajax({
url:
"php.php",
data:
"icefilmsURL=" + theUrl,
success:
function(response){
var movieTitle = $(response).find("#videotitle").find("span:first").text();
$("#container").append("<a href='http://www.icefilms.info/ip.php?v="+theUrl+"' target='blank'>"+movieTitle+"</a><br>");
},
complete:
function(){
if(currNum < maxNum+1){
scrapeThis(generateNextUrl());
}
},
error:
function(xhr,err){
$("#container").append("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
$("#container").append("responseText: "+xhr.responseText);
}
});
};
});
php.php
<?php
echo file_get_contents("http://www.icefilms.info/ip.php?v=".$_GET["icefilmsURL"]);
?>
代码运行良好,但这是我在控制台中看到的:
有什么想法吗?
发布于 2015-01-04 11:55:10
您在控制台中看到了这些内容,因为您正在抓取的页面包含对相关路径的引用。
也就是说,与其说
<img src="http://www.icefilms.info/someimage.jpg">
代码是
<img src="someimage.jpg">
因此,当您在自己的域中抓取并显示他们的HTML时,浏览器试图从您的域加载图像,在本例中为localhost。但是您没有服务器上的映像。
您可以使用HTML中的基本href来解决此问题,也可以查找和替换相对路径图像以包含域。
<base href="http://www.icefilms.info/">
https://stackoverflow.com/questions/27769617
复制