【问题标题】:curl is not showing captchacurl 没有显示验证码
【发布时间】:2012-02-29 22:13:23
【问题描述】:

我正在为一家公司创建一个应用程序,该应用程序将在 windows 应用程序中填写表格,并且将向服务器发送一个发布请求以注册用户。

为了发送 POST 请求,我使用了 curl

    private void post_data(string url, string data)
    {
        Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

        Easy e = new Easy();
        Easy.WriteFunction wf = MyWriteFunction;

        e.SetOpt(CURLoption.CURLOPT_URL, url);
        e.SetOpt(CURLoption.CURLOPT_POSTFIELDS, data);
        e.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
        e.Perform();
        e.Cleanup();
    }

    private int MyWriteFunction(byte[] buf, int size, int nmemb, Object extraData)
    {
        StreamWriter sw = new StreamWriter(@"curl.txt");

        foreach (byte b in buf)
        {
            sw.Write(((char)b));
        }
        sw.Flush();
        sw.Close();

        return buf.Length;
    }

为了从源代码中提取验证码图片路径,让用户输入文字

    private void Get_Captcha_Image(string url)
    {
        Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

        Easy e = new Easy();
        Easy.WriteFunction wf = MyWriteFunction;
        e.SetOpt(CURLoption.CURLOPT_URL, url);
        e.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
        e.Perform();
        e.Cleanup();

        get_ca_2();
    }

    private void get_ca_2()
    {
        Regex r = new Regex(@"(?<=src=('|""))https?://.*?(?=\1)");

        foreach (string line in File.ReadAllLines("curl.txt"))
        {
            Match m = r.Match(line);

            if (m.Success)
            {
                if (m.Value.Contains("http://www.google.com/recaptcha/api/image?c="))
                {
                    pictureBox1.ImageLocation = m.Value;
                }
            }
        }
    }

但我注意到的是

<img width="300" height="57" src="http://www.google.com/recaptcha/api/image?c=03AHJ_VuvnenuZSRbfL_JTQLTYKFYzEFTkYrDgedu0SLyYvTDhsr2hHjQPwYlGJiP3dJRewkIhhdeILAd1_61_aFfU2dclbf8uovme-0gF3nm8Y7-LQVfaDQoI35bo3c35pOnF-xSY3Qfy_lh8TzhSWlMemEnkYnDpZw" alt="reCAPTCHA challenge image" style="display:block;">

例如在使用 curl 提取的网页源代码中不存在

我厌倦了网络浏览器并将其隐藏,我能够找到验证码图像,并且我成功发布了数据,但我需要在 curl 上找到它

【问题讨论】:

    标签: c# regex curl http-post libcurl


    【解决方案1】:

    我会调查网站内容是否会根据您的标题发生变化。显然 curl 的标头看起来与 IE 的标头非常不同。尝试使用允许您伪造不同的用户代理等的浏览器,看看是否会改变它。这可能就像使用 curl 的 --user-agent 标志一样简单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-08
      • 2017-08-02
      • 1970-01-01
      • 2014-12-08
      • 1970-01-01
      • 2020-02-25
      • 2019-04-19
      • 1970-01-01
      相关资源
      最近更新 更多