gpt4 book ai didi

excel - 在编译以下代码时,我有一个错误对象变量或未设置 block 变量

转载 作者:行者123 更新时间:2023-12-04 22:23:37 25 4
gpt4 key购买 nike

 Sub GetJobDetails()
Const URL$ = "https://www.linkedin.com/jobs/search/?geoId=103644278&keywords=nav&location=United%20States&start="
Dim IE As Object: Set IE = CreateObject("InternetExplorer.Application")
Dim post As Object, elem$, R&, I&: I = 0
Do
With IE
.Visible = True
.navigate URL & I
While .Busy Or .readyState < 4: DoEvents: Wend

On Error Resume Next
elem = .document.getElementsByTagName("li")(0).innerText
On Error GoTo 0

If elem = "" Then Exit Do

For Each post In .document.getElementsByTagName("li")
R = R + 1: Cells(R, 1) = post.getElementsByClassName("js_focusable")(0).innerText
Cells(R, 2) = post.getElementsByClassName("job-card-search__company-name-link")(0).innerText
Cells(R, 3) = post.getElementsByClassName("job-card-search__location")(0).innerText
Next post
End With
I = I + 25
elem = ""
Application.Wait Now + TimeValue("00:00:05")
Loop
IE.Quit
End Sub

究竟是什么

"Object variable or with block variable not set"



意思是,可能是网址错误,网址会像上次一样动态变化
“开始 =25/50/75”

最佳答案

要从下一页获取内容,您需要先登录该站点。好消息是您可以使用比 IE 快得多的 xhr 解析登录页面中的内容。

工作脚本(仅来自第一页的内容):

Sub GetJobDetails()
Const URL$ = "https://www.linkedin.com/jobs/search/?geoId=103644278&keywords=nav&location=United%20States&start=0&redirect=false&position=1&pageNum=0"
Dim Html As New HTMLDocument, Htmldoc As New HTMLDocument
Dim I&, R&

With CreateObject("MSXML2.XMLHTTP")
.Open "GET", URL, False
.setRequestHeader "User-Agent", "Mozilla/5.0"
.send
Html.body.innerHTML = .responseText

With Html.querySelectorAll("li.job-result-card")
For I = 0 To .Length - 1
Htmldoc.body.innerHTML = .Item(I).outerHTML
R = R + 1: Cells(R, 1) = Htmldoc.querySelector(".screen-reader-text").innerText
On Error Resume Next
Cells(R, 2) = Htmldoc.querySelector("h4.result-card__subtitle > a").innerText
On Error GoTo 0
Cells(R, 3) = Htmldoc.querySelector("span.job-result-card__location").innerText
Next I
End With
End With
End Sub

在执行上述脚本之前,请确保添加以下引用:
Microsoft HTML Object Library

再一次,您需要登录该站点以解析下一页的内容。

关于excel - 在编译以下代码时,我有一个错误对象变量或未设置 block 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60163474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com