1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| * using System;
* using System.IO;
* using System.Net;
* using System.Text;
* using System.Windows.Forms;
* using mshtml; // Contains the Internet Explorer reference
* using SHDocVw; // Contains the Internet Explorer reference
*
*
*
*
* namespace WebBrowser1
* {
* /// <summary>
* /// Ce module de class permet de naviguer sur internet de maniere automatique
* /// #######################Julien Lembo#######################################
* /// j'ai adapté en C# ce module qui etait initialement crée en Visual Basic par Emelaz
* /// </summary>
* public class web
* {
*
* //Declaration
* string url;
* bool launched;
* string errorMsg;
* InternetExplorer iexplorer;
* HTMLDocument myDoc;
*
* //Lancement de IE dans une nouvelle fenetre
* private void ieStart(){
* try{
* if (launched == false)
* {
* iexplorer = new InternetExplorerClass();
* launched = true;
* }
* else
* {
* errorMsg = "Explorateur deja lancé";
* }
* }
* catch (Exception ex ){
* errorMsg = ex.Message.ToString();
* }
* }
*
* //permet la navigation sur Internet explorer
* public void ieNavigate (bool Visible,string Url)
* {
* ieStart();
* object o = null;
* iexplorer.Navigate(Url,ref o,ref o,ref o,ref o);
* iexplorer.Visible = Visible;
* url = Url;
*
* }
* //On quitte la fenetre internet explorer proprement
* public void ieQuit ()
* {
* try
* {
* iexplorer.Stop();
* iexplorer.Quit();
* }
* catch (Exception ex)
* {
* errorMsg = ex.Message.ToString();
* }
* launched = false;
* }
*
*
*
* // On attrape le code Html de la page Web en cour (attention C pas tres rapide)
* public string ieGetHtml()
* {
* string Url = url;
* WebClient WC = new System.Net.WebClient();
* Stream s = WC.OpenRead(url);
* StreamReader sr = new System.IO.StreamReader(s);
* string CodeSource = sr.ReadToEnd();
* return CodeSource;
* }
*
* //Rempli d'une valeur un champ specifié
* public void ieFillField (string Value ,string FieldName){
*
* try
* {
* myDoc = new HTMLDocumentClass();
* myDoc = (HTMLDocument) iexplorer.Document;
* HTMLInputElement otxtSearchBox = (HTMLInputElement) myDoc.all.item(FieldName, 0);
* otxtSearchBox.value = Value;
* }
* catch(Exception ex){
* errorMsg = ex.Message;
* }
* }
*
*
* //Permet de faire un clique sur le bouton
* public void ieButtonSubmit (string ButtonName){
*
* try
* {
* HTMLInputElement btnSearch = (HTMLInputElement) myDoc.all.item(ButtonName, 0);
* btnSearch.click();
* }
* catch(Exception ex){
* errorMsg = ex.Message;
* }
* }
*
* //On affiche les Messages d'erreurs
* public string ErreurMessage(){
* return errorMsg;
* }
*
*
* }
* }
*
* //####################dans le form###############
* web Iexplorer = new web();//dans le constructeur
* //...
* private void button1_Click(object sender, System.EventArgs e)
* {
* Iexplorer.ieNavigate(true,"http://www.google.fr");
* Iexplorer.ieFillField("google","q");
* Iexplorer.ieButtonSubmit("btnG");
*
*
*
* }
* |
Partager