这段代码有什么问题:
Public Sub GetInfo()
Dim IE As Object, html As Object
With CreateObject("InternetExplorer.Application")
.Visible = True
.navigate "https://pl.pons.com/tłumaczenie"
While .Busy Or .readyState < 4: DoEvents: Wend
Set html = CreateObject("htmlfile")
Set html = .document
With html
.getElementsByTagName("span")(22).Click
.getElementsByTagName("span")(109).Click
.getElementByID("q").Value = "rower"
.querySelector("button.btn.btn-primary.submit").Click
Application.Wait Now + TimeSerial(0, 0, 3)
translation = .getElementsByTagName("dd")(0).innerText
Stop
End With
.Quit
End With
End Sub
可以工作,但没有得到预期结果
发布于 2018-06-01 18:24:04
要获得名词和动词的转化,可以使用以下内容:
translation = Application.WorksheetFunction.Trim(Split(.querySelector("dd > div > div").innerText, vbCrLf)(0))
它将从translation输出DIV中获取所有结果,并通过换行符分割并取第一个结果。最后,删除此结果中的所有前导和尾随空格。
https://stackoverflow.com/questions/-100004711
复制相似问题