Excel 从字典网站检索数据
我目前正在学习托福。我想做的是把单词写到excel中,然后从网站上用土耳其语检索它们的意思。以下是我到目前为止所做的Excel 从字典网站检索数据,excel,vba,Excel,Vba,我目前正在学习托福。我想做的是把单词写到excel中,然后从网站上用土耳其语检索它们的意思。以下是我到目前为止所做的 Sub tureng() Dim ieObj Set ieObj = CreateObject("InternetExplorer.Application") Dim kelime As String Dim sht As Worksheet Set sht = ThisWorkbook.Sheets("Sayfa1") For i = 1 To sht.Range("A10
Sub tureng()
Dim ieObj
Set ieObj = CreateObject("InternetExplorer.Application")
Dim kelime As String
Dim sht As Worksheet
Set sht = ThisWorkbook.Sheets("Sayfa1")
For i = 1 To sht.Range("A10000").End(3).Row
kelime = sht.Cells(i, 1).Value
With ieObj
.Visible = True
.Navigate "http://tureng.com/tr/turkce-ingilizce/" & kelime
Do While .Busy Or .readyState <> 4
DoEvents
Loop
End With
Next
End Sub
Sub-tureng()
Dim ieObj
设置ieObj=CreateObject(“InternetExplorer.Application”)
将kelime变为字符串
将sht变暗为工作表
Set sht=thishworkbook.Sheets(“Sayfa1”)
对于i=1至短量程(“A10000”)。结束(3)行
kelime=短单元格(i,1).值
与ieObj
.Visible=True
.导航“http://tureng.com/tr/turkce-ingilizce/“&kelime
请稍等片刻。忙碌或。准备就绪状态4
多芬特
环
以
下一个
端接头
有了这些代码,我可以打开所需的网站,但我不知道如何获取其含义。我只想知道前两三个字。含义将与主词在同一行,但可以在单独的列中。根据您的回答,下面是一些改进的代码,它具有简单的错误处理,并且更容易适应给定数量的单词(在您的示例3中)。请注意,这是未经测试的,但基于您所说的正在工作的代码(以及您已删除的代码)
Sub-tureng()
作为对象的Dim ieObj
设置ieObj=CreateObject(“InternetExplorer.Application”)
将allRowOfData设置为对象
将kelime变为字符串
将sht变暗为工作表
'如果在工作表中立即使用这些值,则不需要存储它们
Set sht=thishworkbook.Sheets(“Sayfa1”)
作为整数的Dim i
作为整数的Dim j
对于i=1至短量程(“A10000”)。结束(3)行
kelime=短单元格(i,1).值
与ieObj
.Visible=False
.导航“http://tureng.com/tr/turkce-ingilizce/“&kelime
请稍等片刻。忙碌或。准备就绪状态4
多芬特
环
设置allRowOfData=ieObj.document.getElementsByClassName(“tr ts”)
'非常简单的错误处理代码,即使失败也只需尝试3次
出错时继续下一步
对于j=1到3'的回路,最多可获得3个值
单元格(i,j+1).Value=allRowOfData(j).innertext
下一个j
错误转到0
以
接下来我
伊奥布,退出
端接头
Sub tureng()
Dim ieObj As Object
Set ieObj = CreateObject("InternetExplorer.Application")
Dim allRowOfData As Object
Dim kelime As String
Dim sht As Worksheet
' If you are using the values immediately in your sheet, you don't need to store them
Set sht = ThisWorkbook.Sheets("Sayfa1")
Dim i as Integer
Dim j as Integer
For i = 1 To sht.Range("A10000").End(3).Row
kelime = sht.Cells(i, 1).Value
With ieObj
.Visible = False
.Navigate "http://tureng.com/tr/turkce-ingilizce/" & kelime
Do While .Busy Or .readyState <> 4
DoEvents
Loop
Set allRowOfData = ieObj.document.getElementsByClassName("tr ts")
' Very simple error handling code, simply try 3 times regardless of failure
On Error Resume Next
For j = 1 to 3 ' Loop to get up to 3 values
sht.Cells(i, j+1).Value = allRowOfData(j).innertext
Next j
On Error GoTo 0
End With
Next I
ieObj.Quit
End Sub