简体   繁体   English

从网页中获取一些数据并使用 php 或 node.js 将数据存储到 json 文件中

[英]Fetch some data from webpage And store the datas into json file using php or node.js

i input some phone number on http://www.dndstatus.com/dnd-check-process.php and after submiting it shows details like DND status,network operator and Telecom Circle.我在http://www.dndstatus.com/dnd-check-process.php上输入了一些电话号码,提交后会显示 DND 状态、网络运营商和电信圈等详细信息。 I want to fetch these details from the resulting webpage ( http://www.dndstatus.com/dnd-check-process.php?num=9721395967 ) and store to a json file.我想从结果网页( http://www.dndstatus.com/dnd-check-process.php?num=9721395967 )中获取这些详细信息并存储到 json 文件中。 How can i do that??我怎样才能做到这一点??

    /* gets the data from a URL */
    function get_data($url) {
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
$strDetails = get_data("http://www.dndstatus.com/dnd-check-process.php?num=9721395967");

Alternatively, you can use the file_get_contents function remotely, but many hosts don't allow this.或者,您可以远程使用file_get_contents函数,但许多主机不允许这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM