本文介绍了如何在Excel VBA中进行网页抓取时在时间选择器中选择时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用excel VBA从下面的时间选择器中选择09.我已经到了下面的行,但不知道如何进行.任何帮助将不胜感激.

I am trying to select 09 from the time picker below using excel VBA. I have got as far as the line below but do not know how to proceed. Any assistance would be greatly appreciated.

Set e = appIE.document.getElementbyid("timepicker-pickup")


<div class="timepicker" id="timepicker-pickup">
        <div class="arrow"></div>
        <div class="icon close-btn"></div>
        <div class="inner-time-picker clearfix">
            <div class="section hours">
                <div class="up-arrow"><span class="icon arrow"></span></div>
                <div class="selectors">
                    <ul>
                        <li data-value="00">00</li>
                        <li data-value="01">01</li>
                        <li data-value="02">02</li>
                        <li data-value="03">03</li>
                        <li data-value="04">04</li>
                        <li data-value="05">05</li>
                        <li data-value="06">06</li>
                        <li data-value="07">07</li>
                        <li data-value="08" class="selected">08</li>
                        <li data-value="09">09</li>
                        <li data-value="10">10</li>
                        <li data-value="11">11</li>
                    </ul>
                </div>
                <div class="down-arrow"><span class="icon arrow"></span></div>

推荐答案

CSS选择器:

CSS selectors:

尝试选择器#timepicker-pickup li:nth-child(10)

appIE.document.querySelector("#timepicker-pickup li:nth-child(10)").Click

#表示className,因此选择className timepicker-pickup

The # means className and so selects the 10th li tag within element with className timepicker-pickup

或选择器#timepicker-pickup [data-value='09']

appIE.document.querySelector("#timepicker-pickup *[data-value='09']").Click

这只是我在timepicker-pickup

我测试了最新的作品.

CSS选择器:

VBA代码:

Public Sub test()
    Dim ieApp As InternetExplorer, URL As String

    URL = "https://www.europcar.co.za/"
    Set ieApp = New InternetExplorer

    With ieApp
        .Visible = True
        .navigate URL
        While .Busy Or .readyState < 4: DoEvents: Wend

        .document.querySelector("#timepicker-pickup [data-value='09']").Click

        Stop '<== Delete me
        '.Quit <'== Uncomment me
    End With
End Sub

这篇关于如何在Excel VBA中进行网页抓取时在时间选择器中选择时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:05