医药CRM系统开发

自已做医药CRM系统有四年了,终于可以算个产品了,努力市场化,今年重种将医药营销的理念加入CRM

导航

抓取验证码图片和自动执行select选择事件

Posted on 2011-11-17 14:42  hhq80  阅读(332)  评论(0编辑  收藏  举报

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Web;
using System.Net;
using Sanzond;
using System.Text.RegularExpressions;
using mshtml;

namespace HttpPostGet
{
    public partial class jond : Form
    {
        public jond()
        {
            InitializeComponent();
        }

        private void btnDisplay_Click(object sender, EventArgs e)
        {
            Cmd.CreateDirectory("c:\\xj");
            string url;
            url = txtURL.Text;
            lbPage.Text = "0";
            if (url.Length > 0)
            {
                webBrowserPreview.Navigate(url);
                //等待加载完毕
                //while (webBrowserPreview.ReadyState < WebBrowserReadyState.Complete) Application.DoEvents();
            }
            else
            {
                MessageBox.Show("请输入网址!");
            }
        }


        private void jond_Load(object sender, EventArgs e)
        {

        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            txtURL.Text = "http://www.sanzond.com/tools";
            webBrowserPreview.Navigate("http://www.sanzond.com/tools");
        }


        private void webBrowserPreview_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //listBox1.Items.Add(webBrowserPreview.ReadyState);

            while (webBrowserPreview.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }  


            //if (webBrowser1.ReadyState < WebBrowserReadyState.Complete || webBrowser1.Url.ToString() == LastUrl) return;
            //LastUrl = webBrowser1.Url.ToString();

            if (webBrowserPreview.ReadyState == WebBrowserReadyState.Complete)
            {
                HtmlElement link = webBrowserPreview.Document.GetElementById("pager");

               link.SetAttribute("selectedindex", (Convert.ToInt32(link.GetAttribute("selectedindex"))+1).ToString());
               lbPage.Text = link.GetAttribute("selectedindex").ToString();
               link.InvokeMember("onchange");
               HTMLDocument html = (HTMLDocument)webBrowserPreview.Document.DomDocument;
               IHTMLControlElement img = (IHTMLControlElement)webBrowserPreview.Document.Images["Image1"].DomElement;
               IHTMLControlRange range = (IHTMLControlRange)((HTMLBody)html.body).createControlRange();
               range.add(img);
               range.execCommand("Copy", false, null);

               img = null;
               range = null;
               html = null;
             
               if (Clipboard.ContainsImage())
               {
                   this.pictureBox1.Image = Clipboard.GetImage();
                   //if (Clipboard.GetImage().)
                   pictureBox1.Image.Save("c:\\xj\\" +  link.GetAttribute("selectedindex").ToString() + ".jpg");
                   //pictureBox1.
                   lbPage.Text = Convert.ToString(Convert.ToInt32(lbPage.Text) + 1);
                   Clipboard.SetImage(null);
               }
               else
               {
                   MessageBox.Show("执行不成功");
               }

               Clipboard.Clear();

       

            }
        }


    }
}