Solved

Extract part of a HTML document

Posted on 2013-12-30
2
262 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

837 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