Solved

Extract part of a HTML document

Posted on 2013-12-30
2
265 Views
Last Modified: 2014-01-17
Ive written a Powershell script to get information off a webpage (logs in, and navigates to the correct page), my problem is I now have a HTML document of 255 lines, and I only want 15 lines.

The contact is in a table between:-
<!-- #BeginEditable "Content...Area" -->
and
<!-- #EndEditable -->

The table has no ID or Names that I can try and extract data from, there is a title element above the table which reads  '<p>Tree Number: 8</p>', but thought it would be easier to pull the HTML data from between the two "<!-- -->" and then extract the data from the cells like:-
     $tdData = $htmlPulled.getElementsByTagName("td")
     $userID = $tdData(4).innerhtml()
     $userName = $tdData(5).innerhtml()
     $userNumber = $tdData(6).innerhtml()

Open in new window


Only problem is I have no idea how to extract part of the html document and keep it as a html document so I can pull the elements out.

Any ideas?

Thank you
0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Expert Comment

by:DamjanDemsar
ID: 39745824
Hmm, Maybe you can extract the data using
Select-string with -pattern switch (to find the line) and -context switch (to give you addtional lines, you get the following 15 lines using 0,15).


if you need, you can probably add html headers and selected lines into a variable or a file, and then extract them from there.


Cheers
0
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 39747204
This might help for capturing the 15 (or however many) lines.
$filename = "file.html"
[regex]::matches((gc $filename | out-string),'(?s)<!-- #BeginEditable "Content\.\.\.Area" -->(?<lines>.+?)<!-- #EndEditable -->') | % { $_.Groups["lines"].value }

Open in new window

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question