>  기사  >  백엔드 개발  >  开发chrome 插件,抓取部分网页信息,抓取到的信息如何写入文件?

开发chrome 插件,抓取部分网页信息,抓取到的信息如何写入文件?

WBOY
WBOY원래의
2016-06-23 13:49:031016검색

目前有一种方法,用jquery ajax传给服务端,服务端用php写入Excel。但是,现在服务端根本收不到ajax信息,请大师分析原因。

Ps: 已搭建WampServer 环境,也已测试localHost。
贴上服务端PHP代码:(网上找的demo)

header("content-type:application/json; charset:utf-8");
date_default_timezone_set("Asia/Shanghai");
$firstAccess = null;
$rawData = file_get_contents("php://input");
$parameters = json_decode($rawData);
if($parameters){
if(isset($parameters->url)){
$currMd5 = md5($parameters->url);
$handle = fopen("history.txt", "r+");
if ($handle) {
while (($line = fgets($handle, 4096)) !== false) {
if(0===strpos($line, $currMd5)){
$firstAccess = trim(substr($line, 33));
break;
}
}
if(!$firstAccess){
$firstAccess = date("Y-m-d H:i");
fwrite($handle, $currMd5." ".$firstAccess."\r\n");
}
fclose($handle);
}
else {
exit(json_encode(array ('error'=>'服务器意外错误.')));
}
exit(json_encode(array ('firstAccess'=>$firstAccess)));
}
}
exit(json_encode(array ('error'=>'请求不正确.')));
?>


回复讨论(解决方案)

有碰到过同样问题的兄弟吗?求有经验的大哥帮忙?(小弟是PHP新手)

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.