【问题标题】:Retrieve Data from a dictionary website从字典网站检索数据
【发布时间】:2017-01-03 12:40:38
【问题描述】:

我目前正在学习托福。我想做的是写单词以超越并从网站上用土耳其语检索它们的含义。这是我到目前为止所做的。

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

使用这些代码,我可以打开所需的网站,但我不知道如何获取含义。我只想得到前两三个词。含义将与主要单词在同一行,但它们可以在单独的列中。

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    根据您的回答,这里有一些改进的代码,它具有简单的错误处理,并且更容易适应给定数量的单词(在您的示例 3 中)。请注意,这是未经测试的,但基于您所说的有效代码(并且您已删除)...

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 2022-01-19
      • 2013-06-06
      相关资源
      最近更新 更多