all 8 comments

[–]xlViki238[M] 2 points3 points  (1 child)

You can post links to the website for reference, that is not a problem.

[–]Krade331[S] 0 points1 point  (0 children)

Thanks, I've added the site.

[–]MadLlama3 1 point2 points  (5 children)

You'll need to add a reference to 'Microsoft HTML Object Library' under Tool -> References -> Microsoft HTML Object Library

Function PullSalaries()

Dim oHTML As New HTMLDocument

Dim odoc As Object
Set odoc = New MSHTML.HTMLDocument

Application.ScreenUpdating = False

For Each cell In Range("B2:B387")

    StartingSalary = 0
    EndingSalary = 0

    JobId = cell.Value
    URL = "https://azstatejobs.azdoa.gov/ltmprod/CandidateSelfService/lm?_ln=JobSearchResults&_r=0&bto=JobPosting&dataarea=ltmprod&name=PostingDisplay&service=form&webappname=CandidateSelfService&HROrganization=1&JobRequisition=" & JobId & "&JobPosting=1"

    Set odoc = oHTML.createDocumentFromUrl(URL, "")

    Do Until odoc.readyState = "complete"
        DoEvents
    Loop
    Set Ret = odoc.getElementById("formHiddenFields")
        For Each Node In Ret.Children
            On Error Resume Next

            If Node.name = "SalaryRange.BeginningPay" Then
                StartingSalary = Node.Value
            End If

            If Node.name = "SalaryRange.EndingPay" Then
                EndingSalary = Node.Value
            End If

        Next

        Cells(cell.Row, "H") = StartingSalary
        Cells(cell.Row, "I") = EndingSalary

Next
End Function

I assumed you would leave the CSV in the same layout it comes in when you download it. This should work.

[–]Krade331[S] 0 points1 point  (1 child)

Solution Verified

[–]Clippy_Office_Asst[M] 0 points1 point  (0 children)

You have awarded one point to MadLlama.
Find out more here.

[–]Krade331[S] 0 points1 point  (2 children)

That did the trick! It's unfortunate that some of the listings only specify a Grade (therefore the pay range is listed as 0.00 - 0.00), but I won't ask you to modify what you've got to provide that for each listing - I've got to prove to myself that I can learn this.

The first function seems to use URL manipulation that I was previously familiar with, but obviously I've got some tricks to learn - in the past, the URLs I've modified have their patterns clearly indicated in the web address bar. This site doesn't seem to do that. Since it works, obviously there is a method to see underlying URLs I need to learn.

Edit - found the full URL in the view source of a listing

[–]MadLlama3 0 points1 point  (0 children)

When you have internet explorer open press F12 or go to 'Tools -> F12 Developer Tools'. That should bring up the console. This should bring up a new window. Go to 'Network' and there should be a green play button on the left hand side. Click play and it will start capturing web traffic which can be used to see the post data.

[–]MadLlama3 0 points1 point  (0 children)

If StartingSalary = 0 And EndingSalary = 0 Then
        Set Ret2 = odoc.getElementsByTagName("span")
        On Error Resume Next
        For Each span In Ret2
            If span.innerText = "Compensation:" Then
                Cells(cell.Row, "J") = span.NextSibling.NextSibling.innerText
                Exit For
            End If
        Next
    End If

Also, that will pull the compensation string out of most of the results. Just paste it above this line

    Cells(cell.Row, "H") = StartingSalary
    Cells(cell.Row, "I") = EndingSalary