Home > Backend Development > PHP Tutorial > 开发chrome 插件,抓取部分网页信息,抓取到的信息如何写入文件?

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

WBOY
Release: 2016-06-23 13:49:03
Original
1091 people have browsed it

目前有一种方法,用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新手)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template