dtnnpt11795 2018-07-28 09:36
浏览 37
已采纳

如何通过php curl登录这个网站?

I'm trying to log in here that http://www.wemakeprice.com/ by curl, but i don't know what where send data for login and where i get receve to login cookie

some site is easy because can see where send to login form data by network tap in Developer Tools

but that site is cen't find where i send data for login.

i'm looking for Helpful document about this Problem

can you give me advice?

Thanks for look.

  • 写回答

1条回答 默认 最新

  • dongli8466 2018-07-28 10:55
    关注

    Try this snippet I wrote, replace username and password with your corresponding credentials, and replace the URL with the page you want to grab data from (a page that requires a login).

    Check the post data that is sent in browser inspector. Replace $postinfo with the correct post data to ensure you are sending the right data. "email" and "Password" as the $postdata might not work for the site you are trying to login into. If you have trouble, post the inspector's data that is reported in the network tab and I'll try and help.

        $username = "email@example.com";
        $password = "MyPassword123";
    
        $dir = $_SERVER['DOCUMENT_ROOT']."/ctemp";
    
        $path = tempnam(sys_get_temp_dir(), 'MyTempCookie');
    
        $url = "https://www.example.com/dashboard/";
        $postinfo = "email=".$username."&Password=".$password;
    
        $cookie_file_path = $path."/cookie.txt";
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_NOBODY, false);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        //for certain features, set the cookie the site has - this is optional
        curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
        curl_setopt($ch, CURLOPT_USERAGENT,
            "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
        curl_exec($ch);
    
        curl_setopt($ch, CURLOPT_URL, $url);
        $html_data = curl_exec($ch);
        curl_close($ch);
        echo $html_data;
    

    Here at the end I'm simply just echoing the return html data. But you can do whatever you want with it and search for the data inside the response that you need.

    Edit: Just saw that the site has a recaptcha for their login process. Logging in via cURL is going to be far more complex now since they present the recaptcha code to you in an image. Might want to look into tutorials on spoofing recaptcha data. Good luck.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算