1. 程式人生 > >網抓實例:自動修正系統日期和時間

網抓實例:自動修正系統日期和時間

avi navig IV sna 日期和時間 datetime 日期 explorer col

電腦系統日期和時間,用戶可以自己修改。下面的工具可以自動獲取標準的北京日期和時間,並修正系統時間。

技術分享圖片

代碼:

By 劉永富,QQ群:61840693
Public IE As InternetExplorer
Sub GetDateTime()
    On Error GoTo Err1:
    Dim span_date As MSHTML.HTMLSpanElement
    Dim span_time As MSHTML.HTMLSpanElement
    Dim Sdate As String, Stime As String
    Set
IE = New InternetExplorer With IE .Silent = True .Visible = False .navigate "https://www.baidu.com/s?wd=%E5%8C%97%E4%BA%AC%E6%97%B6%E9%97%B4" While .readyState <> READYSTATE_COMPLETE DoEvents Wend Do Set span_date = .document.getElementsByClassName("
op-beijingtime-date").Item(0) DoEvents If span_date Is Nothing = False Then If IsDate(span_date.innerText) Then Exit Do End If Loop Sdate = Trim(span_date.innerText) Set span_time = .document.getElementsByClassName("op-beijingtime-time
").Item(0) Stime = Trim(span_time.innerText) Date = CDate(Sdate) Time = CDate(Left(Stime, 5) & ":" & Right(Stime, 2)) .Quit End With Exit Sub Err1: MsgBox Err.Description End Sub

附件下載:

下載地址

網抓實例:自動修正系統日期和時間