html
  • powershell
  • powershell-v3.0
  • 2017-07-13 3 views 0 likes 
    0

    J'ai un fichier html personnalisé, avec le code ci-dessous avec balise personnalisée "TBD: comment". Je veux obtenir du contenu de cette balise.Parse balise personnalisée dans le fichier html utilisant powershell

    <HTML> 
    <BODY> 
    <h1> This is a heading </h1> 
    <P id='para1'>First Paragraph with some Random text</P> 
    <P>Second paragraph with more random text</P> 
    <A href="http://Geekeefy.wordpress.com">Cool Powershell blog</A> 
    <TBD:comment name="Title"><h3>Katamma katamma loge kathamma</h3> 
    </TBD:comment> 
    <TBD:comment name="content"><h3>Lorem Ipsum is simply dummy text of the 
    printing and typesetting industry. Lorem Ipsum has been the industry's 
    standard dummy text ever since the 1500s, when an unk</h3> </TBD:comment> 
    </BODY> 
    </HTML> 
    

    Le code ci-dessous ne semble pas fonctionner avec l'étiquette personnalisée.

    enter code here 
    $html = Get-Content "C:\Users\sahuBaba\Desktop\ht.html" -Raw 
    $doc = New-Object -com "HTMLFILE" 
    $doc.IHTMLDocument2_write($html) 
    
    $text = $doc.body.getElementsByTagName("TBD:comment") 
    "Inner Text: " + $text[1].innerText 
    

    pas de sortie. Puis-je avoir une aide s'il vous plait? Merci d'avance.

    Répondre

    0

    Essayez avec regex:

    $regex = New-Object Text.RegularExpressions.Regex "<TBD:comment.+?(>.+?)<\/TBD:comment>", ('singleline', 'multiline') 
    $content = "<your html>" 
    foreach($m in $regex.Matches($content)) { 
        # remove leading '<' 
        $m.Groups[1].Value.Substring(1) 
    } 
    
    +0

    Merci .. cela fonctionne, une petite question de suivi si je veux descendre un nom spécifique pour la même balise <à déterminer: comment name = "Body [0] .BodySection ">. si vous pouvez m'aider à obtenir cela aussi. Ce sera vraiment très utile. Merci d'avance. –

    +0

    Essayez ceci: '$ regex = Nouvel objet Text.RegularExpressions.Regex '. +?) <\/TBD: commentaire>', ('singleline' , 'multiligne') $ content = "" foreach ($ m dans $ regex.Matches ($ content)) { # supprimer '' '' $ m.Groupes [1] .Value.Trim ('" ') $ m.Groupes [2] .Valeur.Substring (1) } ' – hkarask

     Questions connexes

    • Aucun problème connexe^_^