首页 > 代码库 > c#抓取网页验证码
c#抓取网页验证码
代码如下:
public partial class Form3 : Form { private CookieContainer cookie = new System.Net.CookieContainer();//声明一个全局cookie变量 public Form3() { InitializeComponent(); } private void Form3_Load(object sender, EventArgs e) { Bind(); this.label2.Cursor = System.Windows.Forms.Cursors.Hand; } private void Bind() { //读取验证码和cookie string URL = "https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand"; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL); request.CookieContainer = new CookieContainer(); Stream responseStream = ((HttpWebResponse)request.GetResponse()).GetResponseStream(); cookie = request.CookieContainer; string cookiesstr = request.CookieContainer.GetCookieHeader(request.RequestUri); Image original = Image.FromStream(responseStream); Bitmap bitMap = new Bitmap(original); this.pictureBox1.Image = bitMap; responseStream.Close(); } catch (Exception exception) { MessageBox.Show("ERROR:" + exception.Message); } } private void label2_Click(object sender, EventArgs e) { Bind();//刷新 } } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。