0
<div class="primary-title-and-description">
    <h1>
        Title Here
    </h1>

    <p>
        Paragraph Here
    </p>
</div>

Hi

I am trying to get the values within the <h1></h1> only from the <div class="primary-title-and-description">. How do I go about doing that?

Above is just a snippet of code which I use the webClient.DownloadString($URL) to get the above. What powershell command can get me only the output as below? Title Here

1 Answer 1

2

use function like $> Get-Title < put here webpage link >

This will get source-code of webpage and using regex cut everything outside < h1> and < /h1>

Function Get-Title { 
    param([string] $url)
		
    $webClient = New-Object System.Net.WebClient 
    $data = $webClient.downloadstring($url) 
    $title = [regex] '(?<=<h1>)([\S\s]*?)(?=</h1>)' 
    write-Host $title.Match($data).value.trim() 
}

Good Luck


REMEMBER TO MARK ANSWER AS USEFUL IF HELPED

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.