【问题标题】:Error in compiling in VBA "set-defined type not defined"在 VBA 中编译时出错“未定义设置定义的类型”
【发布时间】:2020-02-04 06:58:00
【问题描述】:

在 VBA 中编译代码时,我遇到了一个错误

“未定义用户定义类型”

谁能帮我解决这个问题?

Sub import_ZipRecruiter()

Dim IE As SHDocVw.InternetExplorer
Set IE = New InternetExplorer
 IE.Visible = True
IE.Navigate "https://www.ziprecruiter.com/candidate/search? 
search=ax&location=USA&days=5&refine_by_salary=&refine_by_tags=&refine_by_title=&refine_by_org_name="

Do While IE.ReadyState <> READYSTATE_COMPLETE

DoEvents
Loop

Sheets("Sheet3").Select
Cells.Select
Selection.ClearContents



Dim idoc As HTMLDocument
Set idoc = IE.Document
Dim r As Long, c As Long

Dim just_job_title As IHTMLElement
Dim dts As IHTMLCollection
Set dts = idoc.getElementsByClassName("just_job_title")
c =1 ; r=1

For Each just_job_title In dts

Sheets("Sheet3").Cells(r, c) = just_job_title.innerText
c = c + 1
Next just_job_title

End Sub

【问题讨论】:

标签: excel vba web-scraping data-extraction


【解决方案1】:

尝试以下操作以获得所需的输出。这一次您不应该需要对库的任何引用来执行脚本。

Sub GetJobTitles()
    Const Url$ = "https://www.ziprecruiter.com/candidate/search?%20%20search=ax&location=USA&days=5&refine_by_salary=&refine_by_tags=&refine_by_title=&refine_by_org_name="
    Dim post As Object, R&

    With CreateObject("InternetExplorer.Application")
        .Visible = True
        .navigate Url
        While .Busy Or .readyState < 4: DoEvents: Wend
        For Each post In .document.getElementsByTagName("article")
            R = R + 1: Cells(R, 1) = post.getElementsByClassName("just_job_title")(0).innerText
            Cells(R, 2) = post.getElementsByClassName("name")(0).innerText
            Cells(R, 3) = post.getElementsByClassName("location")(0).innerText
        Next post
        .Quit
    End With
End Sub

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多