title: Use GetElementsByClassName in a script
body: <p>I'm trying to write a PowerShell script to get the text within all the classes named "newstitle" from a website.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>function check-krpano {
      $geturl=Invoke-WebRequest http://krpano.com/news/
      $news=$geturl.parsedhtml.body.GetElementsByClassName("newstitle")[0]
      Write-Host  "$news"
  }
  
  check-krpano
  </code></pre>
  
  <p>It obviously needs much more tweaking, but so far, it doesn't work.</p>
  
  <p>I managed to write an script using GetElementById, but I don't know the syntax for GetElementsByClassName, and to be honest, I haven't been able to find much information about it.</p>
  
  <p><strong>NOTE:</strong></p>
  
  <p>I've ticked the right answer to my question, but that's not the solution that I had chose to use in my script.</p>
  
  <p>Although I was able to find the content within a tag containing a certain class, using 2 methods, they were much slower that searching for links.</p>
  
  <p>Here is the output using Measure-Command:</p>
  
  <ul>
  <li>Search for divs containing class 'newstitle' using parsedhtml.body -> 29.6 seconds</li>
  <li>Search for devs containing class 'newstitle' using Allelements -> 10.4 seconds</li>
  <li>Search for links which its element 'href' contains #news -> 2.4 seconds</li>
  </ul>
  
  <p>So I have marked as useful the Links method answer.</p>
  
  <p>This is my final script:</p>
  
  <pre><code>function check-krpano {
      Clear-Host
      $geturl=Invoke-WebRequest http://krpano.com/news
      $news = ($geturl.Links |Where href -match '\#news\d+' | where class -NotMatch 'moreinfo+' )
      $news.outertext | Select-Object -First 5
  }
  
  check-krpano
  </code></pre>