Grab Content from file

Brass Contributor

 

$url = "https://ww2.kanchanaburi.go.th/personal_board//?page=1&limit=99999"
$outputFilePath = "C:\WatchList\temp\Kanchanaburi Province Government Members.txt"

Invoke-WebRequest -Uri $url -OutFile $outputFilePath
$fileContent = Get-Content -Path $outputFilePath -Encoding UTF8
$fileContent


$startIndex = $fileContent.IndexOf('<div class="col-lg-8 col-md-6 col-sm-6">')
$endIndex = $fileContent.IndexOf('<script type="text/javascript" src="sub/js/scriptbreaker-multiple-accordion-1.js"></script>')

# Check if both start and end indices are found
if ($startIndex -ne -1 -and $endIndex -ne -1) {
    $relevantHtml = $fileContent.Substring($startIndex, $endIndex - $startIndex)

    # Define regular expressions to extract specific details
	
    $namePattern = '(<div class="p-2">ชื่อ : <\/div>)[\s\t\n]*<div class="p-2">(.*?)<\/div>'
	$positionPattern = '(<div class="p-2">ตำแหน่ง : <\/div>)[\s\t\n]*<div class="p-2">(.*?)<\/div>'


    # Use regular expressions to extract the desired information
    $name = [regex]::Match($relevantHtml, $namePattern).Groups[2].Value
    $position = [regex]::Match($relevantHtml, $positionPattern).Groups[2].Value

    # Print the extracted information
    Write-Host "Name: $name"
    Write-Host "Position: $position"
} else {
    Write-Host "Start and/or end indices not found in the HTML content."
}

 

 

1 Reply

Hi @YeuHarng,

 

Welcome to the MS Tech Community.

Please provide further information on what you are searching for 🙂 

 

Thanks in advance,

Schnittlauch