WordPress.com



Function Get-Meaning($keywords){# To insert a Line that will separate one meaning from another$break = '--------------------------------------------------------------------------------------------'$keywords |%{try{# Reinitializing variable so that it doesn't retains old value in case of any errors, leading to logical errors.$data = ''$array = ''$grammer = ''# Grabbing the all web content from the website by passing keyword in the URL $webpage = Invoke-WebRequest "$_" -UseBasicParsing -ErrorVariable +err# Capturing the HTML output$content = $webpage.Content# Playing with HTML output to find the useful information between target HTML tags.$data = ($content | %{ [regex]::matches( $_ , '(?<=<div class="ld_on_collegiate">\s+)(.*?)(?=\s+</div>)' ) } | select -ExpandProperty value)$data = $data.Trim() # Remove white spaces from start and end of string# Getting what Part of the Speech from the webpage$grammer =($content | %{ [regex]::matches( $_ , '<span class="main-fl"><em>\w+</em></span>' ) } | select -ExpandProperty value).replace('<span class="main-fl"><em>','').replace('</em></span>','')# Play with the string to get your data in desired format # Following conditions are to work out on HTML structure differences on all pages while parsing the data# You can add more conditions in case you get errors or improper data post script executionif($data.count -eq 2){ Write-host "`nMEANING - $_" -ForegroundColor Yellow if($data[0]) { $i=1 Write-Host "$($grammer[0]): " -ForegroundColor Red ($data[0].Replace('<p>: ','').replace('</p>','').replace(' : ',':').split('<')[0]).split(':')| %{"$i. $($_.trim())"; $i++}}if($data[1]){ $i=1 Write-Host "$($grammer[1]): " -ForegroundColor Red #($data[1].Replace('<p>: ','').replace('</p>','').replace(' : ',':').split('<')[0]).split(':')| %{"$i. $_"; $i++} $array = ($data[1].Replace('<p class="bottom_entry">','').replace('</p>','').replace('<p>: ','')).split(':') if($array[0] -eq '') { $array = $array[1..$array.Count] $array | %{"$i. $($_.trim())"; $i++} } else { $array | %{"$i. $($_.trim())"; $i++} } } echo "$break" }else{Write-host "`nMEANING - $_" -ForegroundColor Yellow$i=1 Write-Host "$($grammer): " -ForegroundColor Red$array = ($data.Replace('<p class="bottom_entry">','').replace('</p>','').replace('<p>: ','')).split(':')if($array[0] -eq ''){$array = $array[1..$array.Count]$array | %{"$i. $($_.trim())"; $i++}}else{$array | %{"$i. $($_.trim())"; $i++}}echo "$break" }}Catch{Write-Host "An error occured, while loading the meaning" -ForegroundColor Cyan} }} ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download