cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 2018
-
21 juin 2018 à 09:57
Whismeril
Messages postés18416Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention 1 juin 2023
-
24 juin 2018 à 21:49
Je souhaite extraire plusieurs informations.
Test pour l'instant d'extraction
- pour ( $USER1$/check_nrpe ), l'expression régulière ' \$USER1\$\/(?<plugin>[^ ]+)' me permet d'extraire check_nrpe
Par contre, pour (id=320&tri=1>'>0</b></td><td><b>ASU-CHECK-SPECIFIQUE-DISK</b></td>),
comment faire pour extraire
320
le chiffre, ici 3, situé entre &tri=1>'>3</b></td>
les chiffres ou lettres, ici ASU-CHECK-SPECIFIQUE-DISK , situés entre <td><b>ASU-CHECK-SPECIFIQUE-DISK</b></td>
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201826 21 juin 2018 à 14:10
In progress !!!
Création classe
Imports System.Text.RegularExpressions
Public Class ExtractIDSTATE
Public Sub New()
End Sub
Public Sub New(ByVal M As Match)
'Id = M.Groups("id").Value
'Countservice = M.Groups("countservice").Value
'Template = M.Groups("template").Value
Plugin = M.Groups("plugin").Value
End Sub
Public Property Id() As Integer
Public Property Countservice() As Integer
Public Property Template() As String
Public Property Plugin() As String
Public Overrides Function ToString() As String
Return Id & " - " & Countservice & " - " & Template & " - " & Plugin
End Function
End Class
et
Sub InitializeDownload()
' Download de la source ID-State dans la variable texte
WebIDState.Navigate(URL_IDSTATE)
While Not WebIDState.ReadyState = WebBrowserReadyState.Complete
System.Windows.Forms.Application.DoEvents()
End While
Dim texte As String = WebIDState.DocumentText.ToString()
If CDbl(texte.Length.ToString) = 1004 Then
MessageBox.Show("Page Web ID-State non récupérée")
Exit Sub
End If
Thread.Sleep((100))
' Extraction des données à partir de la variable texte
'Dim pattern As String = "addIndex\('(?<trigramme>[A-Z0-9-]{3}) : (?<client>[^']+)','(?<serveur>[^']+)"
Dim pattern As String = " \$USER1\$\/(?<plugin>[A-Za-z0-9-_.]+) "
'Dim pattern As String = "<td><b>(?<id>[0-9]+) \$USER1\$\/(?<plugin>[A-Za-z0-9-_.]+) "
' MatchCollection n'est pas "Linquable" directement, d'où le Cast<Match>
Dim toutesLesLignes As IEnumerable(Of ExtractIDSTATE) = (
From m In Regex.Matches(texte, pattern).Cast(Of Match)()
Where m.Success
Select New ExtractIDSTATE(m))
'MessageBox.Show(toutesLesLignes.Count.ToString)
' Liste des plugins
' Private listofplugin As List(Of ExtractIDSTATE)
listofplugin = (
From l In toutesLesLignes
Group l By l.Plugin Into leGroup = Group Order By Plugin
Select New ExtractIDSTATE With {.Plugin = leGroup.First().Plugin}).ToList()
For Each myplugin In listofplugin
MessageBox.Show(myplugin.Plugin, "myplugin")
Next
MessageBox.Show("coucou")
Me.Close()
End Sub
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201826 22 juin 2018 à 13:53
Salut Whismeril,
Ton pattern testé avec "RegEx Storm" me renvoie correctement les quatre variables (${id}, ${countservice}, ${template} et ${plugin} attendues avec le fichier tronqué mis en exemple.
Par contre, testé avec "mon" script VB.Net et le fichier complet téléchargé de mon serveur distant, c'est NOK !!!
Merci,
Je vais continuer à tester et te tiens au courant.
jean-marc
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201826
>
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 2018 Modifié le 22 juin 2018 à 20:14
Le terme "id=" étant plusieurs fois sur la ligne courante d'extraction, comment écrire le pattern pour prendre en compte "idstate/list_command_service.php?id=" ???
MessageBox.Show(texte.Count.ToString, "me retourne environ 100.000")
' Extraction des données à partir de la variable texte
Dim pattern As String = "idstate.+id=(?<id>\d+)'>(?<countservice>\d+)</b></td><td><b>(?<template>.+)</b></td><td><b>\$.+\$USER1\$\/(?<plugin>[^ ]+)"
' MatchCollection n'est pas "Linquable" directement, d'où le Cast<Match>
Dim toutesLesLignes As IEnumerable(Of ExtractIDSTATE) = (
From m In Regex.Matches(texte, pattern).Cast(Of Match)()
Where m.Success
Select New ExtractIDSTATE(m))
MessageBox.Show(toutesLesLignes.Count.ToString, "me retourne 0")
Bonne soirée,
jean-marc
Whismeril
Messages postés18416Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention 1 juin 2023624 24 juin 2018 à 21:10
Salut Jean-Marc.
le pattern que tu as essayé dans RegexStorn n'est pas exactement le même dans le code VB.
Je ne sais pas où se situe la différence, mais quand j'ai copié l'un dans l'autre j'ai eu ça
Whismeril
Messages postés18416Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention 1 juin 2023624
>
Whismeril
Messages postés18416Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention 1 juin 2023 24 juin 2018 à 21:12
trouvé, il manque
&tri=\d+>'
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201826
>
Whismeril
Messages postés18416Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention 1 juin 2023 Modifié le 24 juin 2018 à 21:25
Bonsoir Whismeril,
J'allais te répondre !!!
J'ai testé toute la journée, pas à pas avec un fichier et trouvé l'anomalie.
Le bon pattern est
Dim pattern As String = "id=(?<id>\d+)&tri=1'>(?<countservice>\d+)</b></td><td><b>(?<template>.+)</b></td><td><b>\$.+\$USER1\$\/(?<plugin>[^ ]+)"
' MatchCollection n'est pas "Linquable" directement, d'où le Cast<Match>
Dim toutesLesLignes As IEnumerable(Of ExtractIDSTATE) = (
From m In Regex.Matches(texte, pattern).Cast(Of Match)()
Where m.Success
Select New ExtractIDSTATE(m))
' Liste des plugins
Dim listofplugins = (
From l In toutesLesLignes
Group l By l.Id Into leGroup = Group Order By Id
Select New ExtractIDSTATE With {.Id = leGroup.First().Id, _
.Countservice = leGroup.First().Countservice, _
.Template = leGroup.First.Template, _
.Plugin = leGroup.First.Plugin}).ToList()
For Each myplugin In listofplugins
MessageBox.Show("Id=" & myplugin.Id & Environment.NewLine & _
"Countservice=" & myplugin.Countservice & Environment.NewLine & _
"Template=" & myplugin.Template & Environment.NewLine & _
"Plugin=" & myplugin.Plugin, "myplugin")
Next