从嵌套的div excel vba中抓取信息

时间:2018-10-03 12:24:11

标签: html excel vba web-scraping

我正在尝试从以下内容中提取开始日期,但是我的代码似乎看不到“嵌套”的div“ daysTips”会有什么帮助。谢谢。

HTML屏幕截图: enter image description here

Sub warranty2()

Dim elements As IHTMLElementCollection
Dim IE As New InternetExplorer
Dim Doc As HTMLDocument

IE.Visible = True
IE.navigate "https://pcsupport.lenovo.com/gb/en/products/laptops-and-netbooks/thinkpad-x-series-laptops/thinkpad-x280-type-20kf-20ke/20ke/20kes5sd09/pc0x5yhz/warranty"

Do
 DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE

Set Doc = IE.document
Set elements = Doc.getElementsByClassName("daysTips")

For i = 0 To elements.Length - 1
 Sheet1.Range("G" & (i + 1)) = elements(i).innerText
Next i

IE.Quit

End Sub

1 个答案:

答案 0 :(得分:0)

您需要先在向下的V形字形上进行点击

enter image description here

HTML:

enter image description here


Option Explicit
Public Sub GetInfo()
    Dim IE As New InternetExplorer
    With IE
        .Visible = True
        .navigate "https://pcsupport.lenovo.com/gb/en/products/laptops-and-netbooks/thinkpad-x-series-laptops/thinkpad-x280-type-20kf-20ke/20ke/20kes5sd09/pc0x5yhz/warranty"

        While .Busy Or .readyState < 4: DoEvents: Wend

        IE.document.querySelector(".icon.icon-s-down").Click

        While .Busy Or .readyState < 4: DoEvents: Wend

        Debug.Print IE.document.querySelector(".daysTips span").innerText
        .Quit 
    End With
End Sub