migrate to git.charlotte.sh
This commit is contained in:
commit
fbd588721e
412 changed files with 13750 additions and 0 deletions
21
automation-sys320/week05/HTMLElementsAndWebRequests.ps1
Normal file
21
automation-sys320/week05/HTMLElementsAndWebRequests.ps1
Normal file
|
@ -0,0 +1,21 @@
|
|||
$scraped_page = Invoke-WebRequest -TimeoutSec 10 http://localhost/ToBeScraped.html
|
||||
|
||||
# 9. get link count
|
||||
#$scraped_page.Links.Count
|
||||
|
||||
# 10. get the links as html elements
|
||||
#$scraped_page.Links
|
||||
|
||||
# 11. get the links and display only the URL and its text
|
||||
#$scraped_page.Links | select outerText, href
|
||||
|
||||
# 12. get out text of every element with tag h2
|
||||
#$h2s=$scraped_page.ParsedHtml.body.getElementsByTagName("h2") | select outerText
|
||||
#$h2s
|
||||
|
||||
|
||||
# 13. print innterText of every div element that has the class as "div-1"
|
||||
$divs1=$scraped_page.ParsedHtml.body.getElementsByTagName("div") | `
|
||||
where { $_.getAttributeNode("class").value -ilike "div-1" } | select innerText
|
||||
|
||||
$divs1
|
47
automation-sys320/week05/ScrapingChamplainClasses.ps1
Normal file
47
automation-sys320/week05/ScrapingChamplainClasses.ps1
Normal file
|
@ -0,0 +1,47 @@
|
|||
function gatherClasses(){
|
||||
|
||||
$page = Invoke-WebRequest -TimeoutSec 2 http://localhost/Courses.html
|
||||
|
||||
# get all tr elements
|
||||
$trs=$page.ParsedHTML.body.getElementsByTagName("tr")
|
||||
|
||||
# array to hold results
|
||||
$FullTable = @()
|
||||
for($i=1; $i -lt $trs.length; $i++){
|
||||
|
||||
# get every td element of current tr element
|
||||
$tds= $trs[$i].getElementsByTagName("td")
|
||||
|
||||
# want to seperate start time and end time from one time field
|
||||
$Times = $tds[5].innerText.split(" - ")
|
||||
|
||||
$FullTable += [pscustomobject]@{"Class Code" = $tds[0].innerText; `
|
||||
"Title" = $tds[1].innerText; `
|
||||
"Days" = $tds[4].innerText; `
|
||||
"Time Start" = $Times[0]; `
|
||||
"Time End" = $Times[1]; `
|
||||
"Instructor" = $tds[6].innerText; `
|
||||
"Location" = $tds[9].innerText; `
|
||||
}
|
||||
}# for loop end
|
||||
$Fulltable = daysTranslator($FullTable)
|
||||
return $FullTable
|
||||
}
|
||||
|
||||
|
||||
function daysTranslator($FullTable){
|
||||
|
||||
for($i=0; $i -lt $FullTable.length; $i++){
|
||||
$Days = @()
|
||||
|
||||
if($FullTable[$i].Days -ilike "M*"){ $Days += "Monday" }
|
||||
if($FullTable[$i].Days -ilike "*T[TWF]*"){ $Days += "Tuesday" }
|
||||
if($FullTable[$i].Days -ilike "*W*"){ $Days += "Wednesday" }
|
||||
if($FullTable[$i].Days -ilike "*TH*"){ $Days += "Thursday" }
|
||||
if($FullTable[$i].Days -ilike "*F*"){ $Days += "Friday" }
|
||||
|
||||
$FullTable[$i].Days = $Days
|
||||
}# for loop end
|
||||
return $FullTable
|
||||
}
|
||||
|
30
automation-sys320/week05/ToCallGatherClasses.ps1
Normal file
30
automation-sys320/week05/ToCallGatherClasses.ps1
Normal file
|
@ -0,0 +1,30 @@
|
|||
(Join-Path $PSScriptRoot .\ScrapingChamplainClasses.ps1)
|
||||
|
||||
$Fulltable = gatherClasses
|
||||
|
||||
# i. all classes taught by Furkan Paligu
|
||||
#$Fulltable | select "Class Code", Instructor, Location, Days, "Time Start", "Time End" `
|
||||
#| where { $_."Instructor" -ilike "Furkan Paligu" }
|
||||
|
||||
# ii. list all classes in JOYC 310 on Mondays, display class code and times, sort by start time
|
||||
#$Fulltable | Where-Object { ($_."Location" -ilike "JOYC 310") -and ($_.days -contains "Monday")} | `
|
||||
#Sort-Object "Time Start" | `
|
||||
#Select-Object "Time Start", "Time End", "Class Code"
|
||||
|
||||
# iii. create list of all instructors that teach at least one course in SYS, NET, SEC, FOR, CSI, DAT.
|
||||
# sort by name and make it unique
|
||||
|
||||
$ITSInstrucotrs = $Fulltable | Where-Object { ($_."Class Code" -ilike "SYS*") -or `
|
||||
($_."Class Code" -ilike "NET*") -or `
|
||||
($_."Class Code" -ilike "SEC*") -or `
|
||||
($_."Class Code" -ilike "FOR*") -or `
|
||||
($_."Class Code" -ilike "CSI*") -or `
|
||||
($_."Class Code" -ilike "DAT*") } `
|
||||
| Sort-Object "Instructor" `
|
||||
| Select-Object "Instructor" -Unique
|
||||
|
||||
|
||||
# iv. group instructors by number of classes they are teaching
|
||||
# sort by num classes teaching
|
||||
$FullTable | Where { $_.Instructor -in $ITSInstrucotrs.Instructor } `
|
||||
| Group-Object "Instructor" | Select-Object Count,Name | Sort-Object Count -Descending
|
Loading…
Add table
Add a link
Reference in a new issue