卷曲没有显示验证码

时间:2012-02-29 22:13:24

标签: c# regex curl http-post libcurl

我正在为一家公司创建一个应用程序,该应用程序将填写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;
    }

为了从源代码中提取Captcha图像路径并让用户输入文本

    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

在提取的网页源代码中不存在

我厌倦了一个webbrowser并隐藏它,我能够找到验证码图像,我成功发布数据,但我需要在卷曲上找到它

1 个答案:

答案 0 :(得分:1)

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

相关问题