如何从网页获取价值?

时间:2017-10-27 10:18:00

标签: excel vba web

我想获取/输入网页的值。

到目前为止,我所有的努力都有效,直到只有网页加载。我对网络一无所知。我无法提供网站链接,因为它是 Intranet 网络。

done lin.e 50是我想要输入的地方

然后点击save button

<td valign="top" class="s bgltgray">
    <textarea id="txtResponse1" name="txtResponse1" cols="80" rows="3" class="s">done lin.e 50.</textarea>
    <input type="submit" id="cmdRespond1" name="cmdRespond1" value="Save" onclick="cmdRespond_click(1);">
    <br> Latest Response By: samyvelu, On: 10/23/2017
</td>

2 个答案:

答案 0 :(得分:1)

你可以试试这个。因为我没有网址,所以无法真正测试它,但是这个代码已经在另一个网址上工作,只是没有textarea标记名称

Sub IEtest()
Dim ie As Object
Dim i, x As Integer
Dim objElement As Object
Dim objCollection As Object

Set ie = CreateObject("InternetExplorer.Application")
With ie
    .Visible = True
    .navigate "" '<--- CHANGE THIS

    Do While ie.busy
        Application.Wait DateAdd("s", 1, Now)
    Loop

    Set objCollection = ie.Document.getElementsByTagName("textarea")

    i = 0

    While i < objCollection.Length
        If objCollection(i).Name = "txtResponse1" Then
            objCollection(i).Value = "Your input" '<--- CHANGE THIS
        End If
        i = i + 1
    Wend

    Set objCollection = ie.Document.getElementsByTagName("input")

    i = 0

    While i < objCollection.Length

        If objCollection(i).Type = "submit" And objCollection(i).Name = "cmdRespond1" Then
            Set objElement = objCollection(i)
        End If
        i = i + 1
    Wend

    objElement.Click
End With
End Sub

答案 1 :(得分:1)

存在ID。使用它们,因为它们是最快的选择器方法。使用InternetExplorerMedium对象

With ie.document
    .getElementById("txtResponse1").value = "yourValue"
    .getElementById("cmdRespond1").Click '.Submit
End With