IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

recuperer une page html


Sujet :

C++Builder

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    237
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 237
    Par défaut recuperer une page html
    Bonjour, je cherche à récupérer une page html à partir d'une url. Mon idée est de faire une TEdit où l'utilisateur doit etre une adresse url et ensuite je click sur un bouton pour récupérer la page html correspondant à l'url!!!

    Est ce quelqu'un est deja confronté a ce genre de problème , ça fait 3 jours que je galère et j'arrive pas a trouver la solution!!

    I need help please.

    Merci d'avance.

  2. #2
    Membre éclairé
    Homme Profil pro
    Consultant technique
    Inscrit en
    Juillet 2002
    Messages
    519
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Consultant technique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2002
    Messages : 519
    Par défaut
    Tu as quelle version de C++Builder ?

    FAQ C++Builder : http://cpp.developpez.com/faq/bcb/?p...tcppwebbrowser
    ou FAQ Delphi : http://delphi.developpez.com/faq/?page=indy_idhttp

  3. #3
    Membre très actif Avatar de Argol_Medusa
    Homme Profil pro
    Ingénieur Radiofréquences
    Inscrit en
    Août 2005
    Messages
    208
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur Radiofréquences
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2005
    Messages : 208
    Par défaut
    si tu as la version 6 ou plus de builder tu peux utiliser un TCppWebBrowser qui te permettra de récupérer le contenu en texte ou en page html

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    237
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 237
    Par défaut
    Citation Envoyé par gandf Voir le message
    Tu as quelle version de C++Builder ?
    J'utilise C++Builder 2010 !!! dont je connais pas encore toutes les composants.

    Si vous avez encore des propositions je suis preneur, et merci pour ce premier coup de main, je vais continuer mes recherches.

  5. #5
    Membre Expert
    Avatar de Crayon
    Inscrit en
    Avril 2005
    Messages
    1 811
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 811
    Par défaut
    Avec C++Builder 2010 il y a TWebBrowser.

    C'est facile a utiliser tu fais seulement:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
        WebBrowser1->Navigate("www.google.com");
    }

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    237
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 237
    Par défaut
    Re-bonjour, je reprends mon besoin : je dois recuperer une page html à partir d'une url entrer par un utilisateur dans un formulaire.
    Alors mon idée est d'entrer l'url dans un TEdit et de recuperer le contenu de la page correspondante dans un TFileStream.
    Mon idée me semble bonne mais j'ai un souci à la compilation, voici mon code et l'erreur que j'ai:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    bool __fastcall TForm1::downloadFile (AnsiString source,AnsiString destination)
    {
    	    TFileStream *F = new TFileStream(destination, fmCreate);
            bool download = false;
     
                    try
                    {
                            HTTPClient->Get(AnsiString(AnsiString(source)).c_str(),F);
                            download=true;
                    }
                    catch (...)
                    {
                            download=false;
                    }
     
     
     
    		return download;
    }
    //------------------------------------------------------------------------

    //Methode qui permet de lancer le chargement:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    void __fastcall TForm1::ButtonClick(TObject *Sender)
    {
     
      URL = TEdit->Text ;
      downloadFile (URL,"c:\\test.txt") ;
    }
    Voici l'erreur que j'ai à la compilation :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    [ILINK32 Erreur] Fatal: Impossible d'ouvrir le fichier 'SHDOCVW_OCX.OBJ'
    Mon but est de recuperer la page html correspondant à l'url pour pouvoir y faire des traitement.
    j'ai besoin de votre aide svp et merci d'avance.

  7. #7
    Membre Expert
    Avatar de Crayon
    Inscrit en
    Avril 2005
    Messages
    1 811
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 811
    Par défaut
    Ok, je reprend mon exemple précédent dans lequel j'ai ajouté le code de la FAQ Comment récupérer le source HTML d'une page affichée dans un TCppWebBrowser ?. Lien qui avait été donné plus haut par gandf.

    Voici donc le code complet:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
        WebBrowser1->Navigate(TEdit->Text.w_str()); // URL dans un TEdit
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::WebBrowser1DocumentComplete(TObject *ASender, const IDispatch *pDisp,
              OleVariant &URL)
    {
        IHTMLDocument3 *html = NULL;
        IHTMLElement *element = NULL;
        BSTR string = L"";
        TWebBrowser *browser = (TWebBrowser*)ASender;
     
        try
        {
            if (browser->Document != NULL)
            {
                OleCheck(browser->Document->QueryInterface(IID_IHTMLDocument3,(LPVOID*)&html));
                OleCheck(html->get_documentElement(&element));
                OleCheck(element->get_outerHTML(&string));
            }
        }
        catch (EOleSysError &eOSE)
        {
            if (element != NULL)
            {
                element->Release();
            }
            if (html != NULL)
            {
                html->Release();
            }
            throw eOSE;
        }
     
        // On sauvegarde le contenu
        TFileStream *FStream;
        try
        {
            FStream = new TFileStream("c:\\test.html", fmCreate | fmOpenWrite);
            FStream->Write(string, SysStringByteLen(string));
        }
        __finally
        {
            delete FStream;
        }
    }
    //---------------------------------------------------------------------------
    N'oublie pas d'inclure ceci:

  8. #8
    Membre éclairé
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    385
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 385
    Par défaut
    Salut,

    je me réjouis de lire vos post,
    merci à vos réponse pertinentes,
    cependant j'ai une petite question à ajouter ici et je m'excuse d'avance de la poser dans une discussion qui n'est pa la mienne:
    ayant cette URL:


    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score

    Est-il possible de résuperer les noms qui sont affichés dans la 6° colonne de la page htm i.e. la colonne (Gene names).

    merci à l'avance.

  9. #9
    Membre émérite
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    573
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 573
    Par défaut
    Ton probleme peut etre contourné
    D abord tu charges ta page dans un browser
    Ensuite tu listes les liens

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    Variant vDocument = CppWebBrowser1->ControlInterface->Document;
    if (((IDispatch *)vDocument) != NULL)
    {
       Variant vLinks = vDocument.OlePropertyGet("Links");
       Variant vLinksCount = vLinks.OlePropertyGet("Length");
       for (int i = 0 ; i < vLinksCount ; i++)
       {
         ListBox1->Items->Add(vLinks.OleFunction("Item",i));
       }
    Cà donne

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score#content
    http://www.uniprot.org/
    http://www.uniprot.org/uniprot/
    http://www.uniprot.org/downloads
    http://www.uniprot.org/contact
    http://www.uniprot.org/help/
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score#
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=mapping
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=batch
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=align
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=blast
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score#
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score#
    http://www.uniprot.org/help/sequence-searches
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=mapping
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=batch
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=align
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=search
    http://www.uniprot.org/help/sequence-alignments
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=mapping
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=batch
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=blast
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=search
    http://www.uniprot.org/help/batch
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=mapping
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=align
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=blast
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=search
    http://www.uniprot.org/help/mapping
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=batch
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=align
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=blast
    http://www.uniprot.org/uniprot/?namespace=uniprot&?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score&tab=search
    http://www.uniprot.org/uniprot/?query=organism%3A9606&sort=score
    http://www.uniprot.org/uniprot/?query=PF00704&sort=score
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22&by=taxonomy
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22&by=keyword
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22&by=go
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22&by=ec
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22&by=pathway
    http://www.uniprot.org/uniref/?query=uniprot%3a(PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22)+identity:1.0
    http://www.uniprot.org/uniref/?query=uniprot%3a(PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22)+identity:0.9
    http://www.uniprot.org/uniref/?query=uniprot%3a(PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22)+identity:0.5
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3A%22Homo+sapiens+[9606]%22&sort=score#
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22&sort=score&format=*
    http://www.uniprot.org/uniprot/?query=pf00704+AND+organism%3A9606+AND+reviewed%3Ayes&sort=score
    http://www.uniprot.org/uniprot/?query=pf00704+AND+organism%3A9606+AND+reviewed%3Ano&sort=score
    http://www.uniprot.org/uniprot/?query=pf00704+AND+organism%3A9606+AND+keyword%3A181&sort=score
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22&offset=25&sort=score
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22&sort=protein+names&desc=no
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22&sort=genes&desc=no
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22&sort=organism&desc=no
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22&sort=length
    http://www.uniprot.org/uniprot/P36222
    http://www.uniprot.org/uniprot/Q9BWS9
    http://www.uniprot.org/uniprot/Q12889
    http://www.uniprot.org/uniprot/Q15782
    http://www.uniprot.org/uniprot/Q01459
    http://www.uniprot.org/uniprot/Q9BZP6
    http://www.uniprot.org/uniprot/Q13231
    http://www.uniprot.org/uniprot/Q5VX50
    http://www.uniprot.org/uniprot/A8MTM3
    http://www.uniprot.org/uniprot/Q5VX51
    http://www.uniprot.org/uniprot/Q59HH5
    http://www.uniprot.org/uniprot/Q86YN0
    http://www.uniprot.org/uniprot/Q53FH2
    http://www.uniprot.org/uniprot/A6NNY3
    http://www.uniprot.org/uniprot/Q6ZNK1
    http://www.uniprot.org/uniprot/Q9NY41
    http://www.uniprot.org/uniprot/A5D6V7
    http://www.uniprot.org/uniprot/B4DQ98
    http://www.uniprot.org/uniprot/B2RA77
    http://www.uniprot.org/uniprot/B4DWY0
    http://www.uniprot.org/uniprot/B2RBF5
    http://www.uniprot.org/uniprot/B4DQD7
    http://www.uniprot.org/uniprot/B4DN31
    http://www.uniprot.org/uniprot/B3KQS3
    http://www.uniprot.org/uniprot/Q9UDJ8
    http://www.uniprot.org/uniprot/?query=PF00704+AND+organism%3a%22Homo+sapiens+%5b9606%5d%22&offset=25&sort=score
    http://www.uniprot.org/help/about
    http://www.ebi.ac.uk/
    http://pir.georgetown.edu/
    http://www.isb-sib.ch/
    http://www.uniprot.org/help/license
    http://www.uniprot.org/contact
    Les liens interessants sont de cette forme
    http://www.uniprot.org/uniprot/Q9UDJ8

    Là il faut traiter les chaines , pas de "?" ( replace /? par zz par exemple)
    toujours "http://www.uniprot.org/uniprot/"

    Une fois les bons liens isolés et par exemple ajoutés dans une listbox
    Les charger successivement dans le browser et recuperer le corps dans un memo

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     Memo1->Clear();
       AnsiString aContenuText = "";
    AnsiString aContenuHTML = "";
    Variant vDocument = CppWebBrowser1->ControlInterface->Document;
    if (((IDispatch *)vDocument) != NULL)
    {
       Variant vBody = vDocument.OlePropertyGet("Body");
       Variant vContenuText = vBody.OlePropertyGet("InnerText");
       Variant vContenuHTML = vBody.OlePropertyGet("InnerHTML");
       aContenuText = vContenuText;
       aContenuHTML = vContenuHTML;
    }
     
     
    Memo1->Text= aContenuText  ;

    Et là , coup de bol , une ligne du tableau html donc du memo est formatée de cette façon
    Gene namesName: CHI3L1

    Reste à chercher "Gene namesName:"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    AnsiString Value ;
    int j ;
    for ( int i=1 ;  i<Memo1->Lines->Count  ; i++ )
    {
    Value = Memo1->Lines->Strings[i];
     
     
    j = Value.AnsiPos("Gene namesName:"); // i vaut 11
    if (j!=0 ){  Memo2->Lines->Add(Memo1->Lines->Strings[i]) ;     }
    }
    Et finalement un replace avec les bons flags
    Voilà

  10. #10
    Membre éclairé
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    385
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 385
    Par défaut
    Merci beaucoup Cedni,

    je vais voir ça de pres.


    merci encore

  11. #11
    Membre émérite
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    573
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 573
    Par défaut
    Parcontre , va falloir gerer le tout en utilisant une fonction
    dans l evenement ondocumentcomplete du browser

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [PHP 4] Recuperer des données au sein d'une page HTML
    Par gilles974 dans le forum Langage
    Réponses: 1
    Dernier message: 10/03/2009, 09h36
  2. Comment recuperer le code source d une page HTML distante en javascript
    Par herbert dans le forum Général JavaScript
    Réponses: 10
    Dernier message: 26/07/2006, 22h26
  3. [MySQL] recuperation des données d'un BD et les affichées ds une page html
    Par moonia dans le forum PHP & Base de données
    Réponses: 8
    Dernier message: 21/04/2006, 12h51
  4. Réponses: 3
    Dernier message: 28/12/2005, 15h29
  5. [CR] Tranfert de formulaire a travers une page HTMl
    Par LIEU dans le forum SAP Crystal Reports
    Réponses: 3
    Dernier message: 12/09/2002, 08h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo