開發chrome 外掛程式,抓取部分網頁資訊,抓取到的資訊如何寫入檔案?

來源:互聯網
上載者:User
目前有一種方法,用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新手)

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.