?
Solved

Extract part of a HTML document

Posted on 2013-12-30
2
Medium Priority
?
270 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 41

Accepted Solution

by:
footech earned 2000 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

Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

719 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