从WebBrowser控件验证码图像转换成一个图片 [英] captcha image from WebBrowser Control into a picturebox

查看:171
本文介绍了从WebBrowser控件验证码图像转换成一个图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够验证码图片放到一个图片框上我的形式,是,我需要放大的图像验证码为visualy障用户的原因。

这似乎是这样一个简单的任务,只需要在网页上的图像,并把它变成一个图片,但它正在变成不那么简单。 我有WebBrowser控件的形式,在网站注册一次,我需要在图片框中验证码图像。问题是,验证码的图像是由JavaScript中,当生成Java脚本然后运行它给人的URL验证码图像。但每次当Java脚本运行时,验证码图像会变化。我只想说验证码的图像,在WebBrowser控件当前页面。

任何帮助将是很大的AP preciated。


这是我的code。

 公共无效FacebookRegistration()
{
  HTMLDOC =(mshtml.HTMLDocument)WBrowser.Document.DomDocument;
  iHTMLCol = HTMLDoc.getElementsByTagName(输入);
  的foreach(IHTMLElement iHTMLEle在iHTMLCol)
  {
    如果(iHTMLEle.getAttribute(姓名,0)!= NULL)
    {
      strAttriName = iHTMLEle.getAttribute(姓名,0)的ToString();
      如果(strAttriName ==名字)
      {
        iHTMLEle.setAttribute(价值,名字,0);
        继续;
      }
      如果(strAttriName ==姓氏)
      {
        iHTMLEle.setAttribute(价值,姓氏,0);
        继续;
      }
      如果(strAttriName ==reg_email__)
      {
        iHTMLEle.setAttribute(价值,EMAILID,0);
        继续;
      }
      如果(strAttriName ==reg_passwd__)
      {
        字符串s = GetRandomString();
        随机RAN =新的随机();
        iHTMLEle.setAttribute(值,S + ran.Next(1111,9999),0);
        打破;
      }
    }
  }
  iHTMLCol = HTMLDoc.getElementsByTagName(选项);
  的foreach(IHTMLElement iHTMLEle在iHTMLCol)
  {
    尝试
    {
      如果(iHTMLEle.innerText.Contains(男性))
      {
        iHTMLEle.setAttribute(选择,选择,0);
      }
      如果(iHTMLEle.innerText.Contains(君))
      {
        iHTMLEle.setAttribute(选择,选择,0);
      }
      随机RAN =新的随机();
      如果(iHTMLEle.innerText.Contains(4))
      {
        iHTMLEle.setAttribute(选择,选择,0);
      }
      随机RAN1 =新的随机();
      如果(iHTMLEle.innerText.Contains(ran1.Next(1920,1985)的ToString()))
      {
        iHTMLEle.setAttribute(选择,选择,0);
      }
    }
    抓住 { }
  }

  iHTMLCol = HTMLDoc.getElementsByTagName(输入);
  INT I = 0;
  的foreach(IHTMLElement iHTMLEle在iHTMLCol)
  {
    字符串s = iHTMLEle.className;
    如果(iHTMLEle.className ==UIButton_Text&放大器;&安培; iHTMLEle.getAttribute(价值,0)的ToString()==注册)
    {
      如果(ⅰ!= 0)
      {
        iHTMLEle.click();
        打破;
      }
      我++;
    }
  }

  私人无效WBrowser_DocumentCompleted(对象发件人,WebBrowserDocumentCompletedEventArgs E)
  {
    如果(CurrentSocial ==脸谱)
    {
      FacebookRegistration();
    }
  }
}
 

在facebook.com的注册页面,有验证码,如果你去到页面的源代码,那么你将只能看到这个:

 <输入类型=隐藏ID =captcha_persist_dataNAME =captcha_persist_data value="AAAAAQAQiCw5zhFGOsVF6TbDBX8d_wAAAGvqENqFy5KkvMip5AIv3QSF7BS7goiHfAC7fTkzr8hW61cq3s1d23Tw7m-WAi-21Uzt1l3frkLf4obBEuZZMwga_hbcUhnWXu4P382QsJ7J0WtAbo5USXWuVjzv_KD1SMyTWhf34AGorQd27dFqZc0a" /?;
 

和在此输入标签,我发现的JavaScript的URL这给验证码网址

  JavaScript的网址: http://api.recaptcha.net/challenge?k=6LezHAAAAAAAADqVjseQ3ctG3ocfQs2Elo1FTa_a&ajax=1&xcachestop=0.31520985781374&authp=nonce.tt.time.new_audio_default&psig=H48rD9d3_QogBfxxKAmzFZ7CG10&nonce=hl77BQn58EsYsPpPwQ2TIA&tt=r3zaWETv27-0igoIw5ndwnHt_W4&time=1256413208&new_audio_default=1
 

如果您浏览此网址,你会得到验证码网址是这样的:

  VAR RecaptchaState = {
挑战 : '02UflxsCli4nYg-oG48n5bNDm6ywMlvE62UwXQssF__eJAfSiv2TXuac-1tbu2FThwakgH65IdExWDy9qyr1sYbRuwyQFZD7Dk1eE_fXuoSn9tliqnYeMq__LEF6-GTEm0H6TChOtvpwL2G3C1BsBriw8FFaKqkaTwbNoJeAfzI_j9qYnPaqtHJYillevhRsxyaQVYfLvqai7p0Sfu3849BFpamlbfE3to3KTXi5cZ0xlmuGkMkuZhvq_GyK_z-ZXq9z_Ls8xZlywN0jlIOsSEvI9QJq_69X-X3Moq9lFBcmqWYaKbf7faRQt19aJGB4DdBC1PqQIC',
超时:25000,
服务器:http://api.recaptcha.net/,
现场:6LezHAAAAAAAADqVjseQ3ctG3ocfQs2Elo1FTa_a,
错误信息 : '',
programming_error:'',
is_incorrect:假的
};

Recaptcha.challenge_callback();
 

和原来的验证码网址是这样的:

<$p$p><$c$c>http://api.recaptcha.net/image?c=027CxC4LbBbzVJKy-1xX_wRBf7Gmi4AvgikDVaKeYjBCmiX4XBzGymWC7XRfWx4LLQgfscKnfeB7U305MhlVN0X4vAkrK84ac3jybRJ3UJPUQ8rnlJOS7lqNqpRpolYSd6WBxMShhrzqbx-5ScL0JAsN7cJRMLMqeQsPHg1QB7g4kp4KxKO1aEONsUibahnCC8baLHGSIYJ5Q1Gcr1MPvJ9i_a5qQCilT1tWXwAKE_fkVGi31_un3OxHbNm9UmMemRp7IZ9C9ZLU4IjMApxVJOWXMYqjt588z_ZVcYG2dtY6Dh0b4R1aAQcp0UXFTggdWtsjPw7wIC

那么你将得到验证码,但不是我想要的,因为JavaScript每次改变capthca图像。所以我不明白这是目前被显示在网页浏览器验证码

解决方案

您可以图像复制到剪贴板进行阅读。另外,您可以解析页面获取图像的URL,看看你是否可以掏图像文件从缓存中

如何以编程方式复制一个IMG元素复制到剪贴板

I need to be able to place the captcha image into a picturebox on my form, the reason being that I need to zoom the captcha image for the visualy impaired users.

It appears to be such a simple task, just take the image from the web page and put it into a picturebox but it is turning out to be not so simple. i have WebBrowser control in form and for registration in one of site, i need captcha image in picture box. problem is that captcha image is generated by JavaScript, when java script runs then it gives url of captcha image. but every time when java script runs, captcha image goes change. i just want that captcha image which is on WebBrowser control current page.

Any help would be greatly appreciated.


here is my code.

public void FacebookRegistration()
{
  HTMLDoc = (mshtml.HTMLDocument)WBrowser.Document.DomDocument;
  iHTMLCol = HTMLDoc.getElementsByTagName("input");
  foreach (IHTMLElement iHTMLEle in iHTMLCol)
  {
    if (iHTMLEle.getAttribute("name", 0) != null)
    {
      strAttriName = iHTMLEle.getAttribute("name", 0).ToString();
      if (strAttriName == "firstname")
      {
        iHTMLEle.setAttribute("value", FirstName, 0);
        continue;
      }
      if (strAttriName == "lastname")
      {
        iHTMLEle.setAttribute("value", LastName, 0);
        continue;
      }
      if (strAttriName == "reg_email__")
      {
        iHTMLEle.setAttribute("value", EmailID, 0);
        continue;
      }
      if (strAttriName == "reg_passwd__")
      {
        string s = GetRandomString();
        Random ran = new Random();
        iHTMLEle.setAttribute("value", s+ran.Next(1111,9999), 0);
        break;
      }
    }
  }
  iHTMLCol = HTMLDoc.getElementsByTagName("option");
  foreach (IHTMLElement iHTMLEle in iHTMLCol)
  {
    try
    {
      if (iHTMLEle.innerText.Contains("Male"))
      {
        iHTMLEle.setAttribute("selected", "selected",0);
      } 
      if (iHTMLEle.innerText.Contains("Jun"))
      {
        iHTMLEle.setAttribute("selected", "selected", 0);
      }
      Random ran = new Random();
      if (iHTMLEle.innerText.Contains("4"))
      {
        iHTMLEle.setAttribute("selected", "selected", 0);
      }
      Random ran1 = new Random();
      if (iHTMLEle.innerText.Contains(ran1.Next(1920,1985).ToString()))
      {
        iHTMLEle.setAttribute("selected", "selected", 0);
      }
    }
    catch { }
  }

  iHTMLCol = HTMLDoc.getElementsByTagName("input");
  int i = 0;
  foreach (IHTMLElement iHTMLEle in iHTMLCol)
  {
    string s = iHTMLEle.className;
    if (iHTMLEle.className == "UIButton_Text" && iHTMLEle.getAttribute("value", 0).ToString() == "Sign Up")
    {
      if (i != 0)
      {
        iHTMLEle.click();
        break;
      }
      i++;
    }
  }

  private void WBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  {
    if (CurrentSocial == "facebook")
    {
      FacebookRegistration();
    }
  }
}

in the registration page of facebook.com, there is captcha and if you go to page source then you will see only this:

<input type="hidden" id="captcha_persist_data" name="captcha_persist_data" value="AAAAAQAQiCw5zhFGOsVF6TbDBX8d_wAAAGvqENqFy5KkvMip5AIv3QSF7BS7goiHfAC7fTkzr8hW61cq3s1d23Tw7m-WAi-21Uzt1l3frkLf4obBEuZZMwga_hbcUhnWXu4P382QsJ7J0WtAbo5USXWuVjzv_KD1SMyTWhf34AGorQd27dFqZc0a" /?;

and in this input tag, i found url of that javascript which gives captcha url

javascript url: http://api.recaptcha.net/challenge?k=6LezHAAAAAAAADqVjseQ3ctG3ocfQs2Elo1FTa_a&ajax=1&xcachestop=0.31520985781374&authp=nonce.tt.time.new_audio_default&psig=H48rD9d3_QogBfxxKAmzFZ7CG10&nonce=hl77BQn58EsYsPpPwQ2TIA&tt=r3zaWETv27-0igoIw5ndwnHt_W4&time=1256413208&new_audio_default=1

if you browse this url you will get captcha url like this:

var RecaptchaState = {
challenge : '02UflxsCli4nYg-oG48n5bNDm6ywMlvE62UwXQssF__eJAfSiv2TXuac-1tbu2FThwakgH65IdExWDy9qyr1sYbRuwyQFZD7Dk1eE_fXuoSn9tliqnYeMq__LEF6-GTEm0H6TChOtvpwL2G3C1BsBriw8FFaKqkaTwbNoJeAfzI_j9qYnPaqtHJYillevhRsxyaQVYfLvqai7p0Sfu3849BFpamlbfE3to3KTXi5cZ0xlmuGkMkuZhvq_GyK_z-ZXq9z_Ls8xZlywN0jlIOsSEvI9QJq_69X-X3Moq9lFBcmqWYaKbf7faRQt19aJGB4DdBC1PqQIC',
timeout : 25000,
server : 'http://api.recaptcha.net/',
site : '6LezHAAAAAAAADqVjseQ3ctG3ocfQs2Elo1FTa_a',
error_message : '',
programming_error : '',
is_incorrect : false
};

Recaptcha.challenge_callback();

and original captcha url look like this:

http://api.recaptcha.net/image?c=027CxC4LbBbzVJKy-1xX_wRBf7Gmi4AvgikDVaKeYjBCmiX4XBzGymWC7XRfWx4LLQgfscKnfeB7U305MhlVN0X4vAkrK84ac3jybRJ3UJPUQ8rnlJOS7lqNqpRpolYSd6WBxMShhrzqbx-5ScL0JAsN7cJRMLMqeQsPHg1QB7g4kp4KxKO1aEONsUibahnCC8baLHGSIYJ5Q1Gcr1MPvJ9i_a5qQCilT1tWXwAKE_fkVGi31_un3OxHbNm9UmMemRp7IZ9C9ZLU4IjMApxVJOWXMYqjt588z_ZVcYG2dtY6Dh0b4R1aAQcp0UXFTggdWtsjPw7wIC

then you will get captcha, but is is not what i want , because javascript everytime changes the capthca image. so i dont get captcha which is currently being shown in webbrowser

解决方案

You can copy the image to the clipboard and read from there. Alternatively you can parse the page to get the image's URL and see if you can dig the image file out of the cache

How To Programmatically Copy an IMG Element to the Clipboard

这篇关于从WebBrowser控件验证码图像转换成一个图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆