Solved

Extract part of a HTML document

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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