Solved

Extract part of a HTML document

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now