这是我用来翻译excell表格中的字段的VBA脚本。问题是这个脚本在2个3个月前对我有效,但现在翻译后IE.Document是空的。页面提供了正确的翻译,但我无法在excel工作表中获得结果
inputstring = "en"
outputstring = "da"
text_to_convert = str
'open website
IE.Visible = True
IE.navigate "https://translate.google.com/#" & inputstring & "/" & outputstring & "/" & text_to_convert
Do Until IE.ReadyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:4"))
Do Until IE.ReadyState = 4
DoEvents
Loop
test = IE.Document.getElementById("result_box")发布于 2019-02-13 19:06:20
使用适当的页面等待。我还使用了不同的元素选择器。
Option Explicit
Public Sub GetTranslation()
Dim ie As New InternetExplorer, ws As Worksheet
Dim inputString As String, outputString As String, text_to_convert As String, translation As String
inputString = "en"
outputString = "da"
text_to_convert = "Banana"
Set ws = ThisWorkbook.Worksheets("Sheet1")
With ie
.Visible = True
.Navigate2 "https://translate.google.com/#" & inputString & "/" & outputString & "/" & text_to_convert
While .Busy Or .readyState < 4: DoEvents: Wend
translation = ie.document.querySelector(".translation").innerText
ws.Cells(1, 1) = translation
.Quit
End With
End Subhttps://stackoverflow.com/questions/54667280
复制相似问题