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 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题