locked
How to read a Header only using PowerShell? RRS feed

  • Question

  • I am getting HTML files using Get-Content. Now I want to read the header only from each HTML file. I would like to copy the header and use it as the file name of the HTML file it comes from.  What steps should I take and is this even possible?

    Friday, July 14, 2017 9:54 AM

All replies

  • If it is HTML 5 you can use XML to extract the header.  If it is not compliant HTML 5 you will have to use RegEx to extract the header.

    Web pages saved to a file do not have headers.  Headers are only available in a web session.  Perhaps you are looking for the contents of the "<head"> tag which is not the same thing as web request headers.

    See: https://4sysops.com/archives/powershell-invoke-webrequest-parse-and-scrape-a-web-page/


    \_(ツ)_/


    Friday, July 14, 2017 10:39 AM
  • Hi breccs

    Just checking in to see if the information provided was helpful.

    Please let us know if you would like further assistance.

    Best Regards,

    Candy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, August 21, 2017 8:45 AM