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

VB.NET Discussion :

HTML vers TEXTE sans balises


Sujet :

VB.NET

  1. #1
    Membre habitué
    Inscrit en
    Janvier 2007
    Messages
    201
    Détails du profil
    Informations personnelles :
    Âge : 79

    Informations forums :
    Inscription : Janvier 2007
    Messages : 201
    Points : 154
    Points
    154
    Par défaut HTML vers TEXTE sans balises
    Bonjour,
    Je cherche à convertir le source d'une page HTML récupérée sur le WEB en un texte débarassé des balises et autres commandes. En faire un document le plus lisible possible. Y-a-t-il une fonction VB qui le réalise, un script déja prêt à l'emploi ou bien dois-je me prendre par la main, le developper et une fois au point le mettre à disposition de tous ?
    Merci

  2. #2
    Membre du Club Avatar de dontDeleteMe
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    80
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Octobre 2006
    Messages : 80
    Points : 63
    Points
    63
    Par défaut
    je n'en connais pas en VB, mais en PHP, il y a la fonction htmlentities()

  3. #3
    Membre à l'essai
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    essaye d'utiliser ca HtmlTextWriter et la fonction ToString

  4. #4
    Membre habitué
    Inscrit en
    Janvier 2007
    Messages
    201
    Détails du profil
    Informations personnelles :
    Âge : 79

    Informations forums :
    Inscription : Janvier 2007
    Messages : 201
    Points : 154
    Points
    154
    Par défaut
    j'va essayer ça. Réponse asap. merci

  5. #5
    Membre habitué
    Inscrit en
    Janvier 2007
    Messages
    201
    Détails du profil
    Informations personnelles :
    Âge : 79

    Informations forums :
    Inscription : Janvier 2007
    Messages : 201
    Points : 154
    Points
    154
    Par défaut
    utiliser HTMLTEXTWRITER, visiblement pas évident ! Je cherche de la doc à ce sujet.

  6. #6
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 6
    Points : 7
    Points
    7
    Par défaut
    J'utilise ce bous de code pour faire ce que tu cherche.
    C'est pas parfait mais c'est un bon début:
    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
    '' Remove HTML Development formatting
                '' Replace line breaks with space
                '' because browsers inserts space
                result = source.Replace("\r", " ")
                '' Replace line breaks with space
                '' because browsers inserts space
                result = result.Replace("\n", " ")
                '' Remove step-formatting
                result = result.Replace("\t", String.Empty)
                '' Remove repeating speces becuase browsers ignore them
                result = System.Text.RegularExpressions.Regex.Replace(result, "( )+", " ")
                '' Remove the header (prepare first by clearing attributes)
                result = System.Text.RegularExpressions.Regex.Replace(result, "<( )*head([^>])*>", "<head>", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "(<( )*(/)( )*head( )*>)", "</head>", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "(<head>).*(</head>)", String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                '' remove all scripts (prepare first by clearing attributes)
                result = System.Text.RegularExpressions.Regex.Replace(result, "<( )*script([^>])*>", "<script>", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "(<( )*(/)( )*script( )*>)", "</script>", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "(<script>).*(</script>)", String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                '' remove all styles (prepare first by clearing attributes)
                result = System.Text.RegularExpressions.Regex.Replace(result, "<( )*style([^>])*>", "<style>", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "(<( )*(/)( )*style( )*>)", "</style>", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "(<style>).*(</style>)", String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                '' insert tabs in spaces of <td> tags
                result = System.Text.RegularExpressions.Regex.Replace(result, "<( )*td([^>])*>", "\t", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                '' insert line breaks in places of <BR> and <LI> tags
                result = System.Text.RegularExpressions.Regex.Replace(result, "<( )*br( )*>", "\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "<( )*li( )*>", "\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                '' insert line paragraphs (double line breaks) in place
                '' if <P>, <DIV> and <TR> tags
                result = System.Text.RegularExpressions.Regex.Replace(result, "<( )*div([^>])*>", "\r\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "<( )*tr([^>])*>", "\r\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "<( )*p([^>])*>", "\r\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                '' Remove remaining tags like <a>, links, images,
                '' comments etc - anything thats enclosed inside < >
                result = System.Text.RegularExpressions.Regex.Replace(result, "<[^>]*>", String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                ''replace special characters:
                result = System.Text.RegularExpressions.Regex.Replace(result, "&nbsp;", " ", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "&bull;", " * ", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "&lsaquo;", "<", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "&rsaquo;", ">", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "&trade;", "(tm)", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "&frasl;", "/", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "&lt;", "<", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "&gt;", ">", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "&copy;", "(c)", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "&reg;", "(r)", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                '' Remove all others. More can be added, see
                '' http://hotwired.lycos.com/webmonkey/reference/special_characters/
                result = System.Text.RegularExpressions.Regex.Replace(result, "&(.{2,6});", String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                '' for testng
                ''System.Text.RegularExpressions.Regex.Replace(result, this.txtRegex.Text,string.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                '' make line breaking consistent
                result = result.Replace("\n", "\r")
                '' Remove extra line breaks and tabs:
                '' replace over 2 breaks with 2 and over 4 tabs with 4. 
                '' Prepare first to remove any whitespaces inbetween
                '' the escaped characters and remove redundant tabs inbetween linebreaks
                result = System.Text.RegularExpressions.Regex.Replace(result, "(\r)( )+(\r)", "\r\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "(\t)( )+(\t)", "\t\t", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "(\t)( )+(\r)", "\t\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                result = System.Text.RegularExpressions.Regex.Replace(result, "(\r)( )+(\t)", "\r\t", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                '' Remove redundant tabs
                result = System.Text.RegularExpressions.Regex.Replace(result, "(\r)(\t)+(\r)", "\r\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                '' Remove multible tabs followind a linebreak with just one tab
                result = System.Text.RegularExpressions.Regex.Replace(result, "(\r)(\t)+", "\r\t", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                '' Initial replacement target string for linebreaks
                Dim breaks As String = "\r\r\r"
                '' Initial replacement target string for tabs
                Dim tabs As String = "\t\t\t\t\t"
                Dim index As Integer
                For index = 0 To index < result.Length
                    result = result.Replace(breaks, "\r\r")
                    result = result.Replace(tabs, "\t\t\t\t")
                    breaks = breaks + "\r"
                    tabs = tabs + "\t"
                Next

  7. #7
    Membre habitué
    Inscrit en
    Janvier 2007
    Messages
    201
    Détails du profil
    Informations personnelles :
    Âge : 79

    Informations forums :
    Inscription : Janvier 2007
    Messages : 201
    Points : 154
    Points
    154
    Par défaut
    merci le petit qui fume. j'essaye tout de suite.

  8. #8
    Membre habitué
    Inscrit en
    Janvier 2007
    Messages
    201
    Détails du profil
    Informations personnelles :
    Âge : 79

    Informations forums :
    Inscription : Janvier 2007
    Messages : 201
    Points : 154
    Points
    154
    Par défaut
    Voila le résultat de la page d'accueil de Google. C'est déja pas mal.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Google
     
     
     
    \r\rPersonnaliser cette page | Connexion\r\r
    \r\r\tWeb    Images    Groupes    Actualit?s    plus \r\r\t \t\r\t  Recherche avanc?e\r  Pr?f?rences\r  Outils linguistiques\r\r\tRechercher dans :  Web  Pages francophones  Pages : France \r\rPublicit? - Solutions d'entreprise - ? propos de Google - Google.com in English\r\r(c)2007 Google
    Donc solutionner la récupération des minuscules accentuées, éliminer des \r

    Merci

  9. #9
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 6
    Points : 7
    Points
    7
    Par défaut
    Personnellement je doit faire 2 passe de ce code pour obtenir un meilleur résultat si tu arrive à faire mieux je suis preneur.

  10. #10
    Membre habitué
    Inscrit en
    Janvier 2007
    Messages
    201
    Détails du profil
    Informations personnelles :
    Âge : 79

    Informations forums :
    Inscription : Janvier 2007
    Messages : 201
    Points : 154
    Points
    154
    Par défaut
    merci Tikismoke, je vais essayer les deux passes, et tacher moyen d'améliorer. A suivre

Discussions similaires

  1. Comment définir le style du texte sans balises ?
    Par Frank74 dans le forum Mise en page CSS
    Réponses: 7
    Dernier message: 09/12/2011, 15h27
  2. Convertisseur HTML vers Texte, ôtez-moi un doute.
    Par Heka-thumbs dans le forum Balisage (X)HTML et validation W3C
    Réponses: 6
    Dernier message: 12/04/2011, 01h09
  3. tableau html avec texte sans feuille de style
    Par grequouine dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 13/12/2009, 16h34
  4. [WD9] Html vers Texte
    Par Romanops dans le forum WinDev
    Réponses: 6
    Dernier message: 20/04/2006, 15h40
  5. [html] Input text sans cadre
    Par G_Kill dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 04/05/2005, 16h13

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