国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開(kāi)通VIP
c# 抓取網(wǎng)頁(yè)驗(yàn)證碼并post數(shù)據(jù)

如果想開(kāi)發(fā)半自動(dòng)的注冊(cè)機(jī)程序,那么把驗(yàn)證碼讀取到winform里面,然后提交數(shù)據(jù)是必須的流程,這篇博文記錄一下如何抓取網(wǎng)頁(yè)上面的驗(yàn)證碼,注意不是驗(yàn)證碼識(shí)別。有的網(wǎng)站會(huì)驗(yàn)證Cookie,有的不會(huì),本文包含Cookie讀取提交。

首先生命一個(gè)全局的Cookie變量

  1. private CookieContainer cookie = new System.Net.CookieContainer();  


程序加載的時(shí)候讀取驗(yàn)證碼和Cookie

  1. public Form1()  
  2.         {  
  3.             InitializeComponent();  
  4.   
  5.             string checkcodeUrl = "驗(yàn)證碼的url";  
  6.   
  7.             try  
  8.             {  
  9.                   
  10.                 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(checkcodeUrl);  
  11.   
  12.                 request.CookieContainer = new CookieContainer();   
  13.   
  14.                 Stream responseStream = ((HttpWebResponse)request.GetResponse()).GetResponseStream();  
  15.   
  16.                 cookie = request.CookieContainer;  
  17.   
  18.                 string cookiesstr = request.CookieContainer.GetCookieHeader(request.RequestUri);   
  19.   
  20.                 Image original = Image.FromStream(responseStream);  
  21.   
  22.                 Bitmap bitMap = new Bitmap(original);  
  23.   
  24.                 this.pictureBox1.Image = bitMap;  
  25.   
  26.                 responseStream.Close();  
  27.   
  28.             }  
  29.             catch (Exception exception)  
  30.             {  
  31.   
  32.                 MessageBox.Show("ERROR:" + exception.Message);  
  33.   
  34.             }  
  35.         }  


提交數(shù)據(jù)

  1. HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);  
  2.             webrequest.CookieContainer = cookie;  
  3.             HttpWebResponse response = (HttpWebResponse)webrequest.GetResponse();  
  4.             StreamReader read = new StreamReader(response.GetResponseStream(), Encoding.Default);  
  5.             string text = read.ReadToEnd();  


如果有看不懂的歡迎留言咨詢,只寫了一部分必須的代碼。

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Python網(wǎng)絡(luò)爬蟲學(xué)習(xí)實(shí)戰(zhàn):爬蟲快速入門
R語(yǔ)言爬蟲系列6|動(dòng)態(tài)數(shù)據(jù)抓取范例
Linux下cURL使用教程之二:HTTP協(xié)議概述
史上最詳細(xì)的抓包教程 看到就是賺到
PHP 中使用CURL實(shí)現(xiàn)GET和POST請(qǐng)求
使用InternetSetCookie 刪除時(shí)一定要傳入path參數(shù)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服