c#實現從其他網站抓取imei碼資訊,手工輸入驗證碼

來源:互聯網
上載者:User

閱讀全文:http://www.yzswyl.cn/blread-1603.html

功能:從其他網站手工輸入驗證碼並抓取手機IMEI資訊

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Net;using System.IO;    namespace getImei{    public partial class Form1 : Form    {        private String imgUrl;        string url = "http://abc.aspx";//抓取的地址        private WebBrowser wb = new WebBrowser();        Uri baseUri;        WebClient wc = new WebClient();            public Form1()        {            InitializeComponent();        }            private void Form1_Load(object sender, EventArgs e)        {            wb.Navigate(url);            wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);            }            //重新擷取驗證碼        private void button1_Click(object sender, EventArgs e)        {             wb.Navigate(url);             wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);            }            private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)        {            if (wb.Document.Url == e.Url)            {                //載入完畢。                HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();                html.LoadHtml(wb.DocumentText);                HtmlAgilityPack.HtmlNode htmlNode = html.DocumentNode;                HtmlAgilityPack.HtmlNode tagImg = htmlNode.SelectSingleNode("//*[@id=\"SNTD\"]/img");                if (tagImg != null)                {                    string imgReUri = tagImg.GetAttributeValue("src", "");                    baseUri = new Uri(url);                    Uri imgUri = new Uri(baseUri, imgReUri);                        byte[] imgData = wc.DownloadData(imgUri);                        pictureBox1.Image = BytesToImage(imgData);                }            }            if (wb.Document.Url.ToString().Contains("Check/IMEIValidateDetail.aspx?a="))            {                //內容                HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();                html.LoadHtml(wb.DocumentText);                HtmlAgilityPack.HtmlNode htmlNode = html.DocumentNode;                HtmlAgilityPack.HtmlNode summary = htmlNode.SelectSingleNode("//table[@class=\"checkContent2\"]");                if (summary != null)                {                    //webBrowser1.DocumentText = summary.InnerText;                    richTextBox1.Text = summary.InnerHtml;                }                    //圖片                HtmlAgilityPack.HtmlNode iframe = htmlNode.SelectSingleNode("//table[@class=\"checkContent2\"]/tr[1]/td[1]/iframe");                if (iframe != null)                {                    string frameRes = iframe.GetAttributeValue("src", "無圖片");                    Uri frameUri = new Uri(baseUri, frameRes);                    string iframePageData = wc.DownloadString(frameUri);                    html.LoadHtml(iframePageData);                    htmlNode = html.DocumentNode;                    HtmlAgilityPack.HtmlNode imgNode = htmlNode.SelectSingleNode("//*[@id=\"imgEQ\"]");                    if (imgNode != null)                    {                        string thumbRes = imgNode.GetAttributeValue("src", "");                        Uri thumbUri = new Uri(baseUri, thumbRes);                        pictureBox2.Load(thumbUri.ToString());                    }                    }            }        }            public static Image BytesToImage(byte[] bytes)        {            MemoryStream ms = new MemoryStream(bytes);            Image img = Image.FromStream(ms);            return img;        }            //抓取IMEI內容        private void button2_Click(object sender, EventArgs e)        {            wb.Document.GetElementById("ctl00$ContentPlaceHolder1$IMEICode").InnerText = "****************";//手機IMET號碼            wb.Document.GetElementById("ctl00_ContentPlaceHolder1_txtValidateCode").InnerText = textBox1.Text;            wb.Document.GetElementById("ctl00_ContentPlaceHolder1_submit").InvokeMember("click");            while (wb.ReadyState != WebBrowserReadyState.Complete)            {                Application.DoEvents();            }        }        //查看詳細資料        private void button3_Click(object sender, EventArgs e)        {            foreach (HtmlElement he in wb.Document.GetElementsByTagName("a"))            {                if ("(查看詳細)".Equals(he.InnerText.Trim()))                {                    he.InvokeMember("click");                    break;                }            }        }                }}

  

控制項

pictureBox1

label1

textBox1

button1

button2

button3

pictureBox2

richTextBox1

引用

下載HtmlAgilityPack,添加引用,:http://htmlagilitypack.codeplex.com/ ,點擊右側的download即可下載

效果

原文:http://www.yzswyl.cn/blread-1603.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.