|
本帖最后由 muziyulin 于 2024-3-20 10:24 编辑
源文件中自动获取http://61.145.246.228:8081/zhjdxt/mainpage/home/gettp.aspx的日期,获取的信息是
现在网址改了,https://zjj.zhuhai.gov.cn/zjj/zwgk/zzjg/jsdw/zhsjsgczljdjcz/,我查看源码的时候发现是https://www.zhjdxt.cn/viewWarning,替换网址会发生错误。麻烦帮忙处理一下。
源VBA:
- Option Explicit
- Sub IE()
- Dim IE As Object, url As String, arr, i As Integer, str As String
- Application.ScreenUpdating = False
- Set IE = CreateObject("InternetExplorer.Application")
- url = "http://61.145.246.228:8081/zhjdxt/mainpage/home/gettp.aspx"
- With IE
- .Visible = False '不可见
- .navigate url '访问
- IEWait IE '等待
- arr = Split(.document.body.innertext, Chr(10)) '页面结果放入数组
- Range("A1").Resize(UBound(arr) + 1, 1) = WorksheetFunction.Transpose(arr) '写入单元格
- Range("1:8,10:10,12:15,17:17").Delete '删除无效行
- For i = 1 To Range("A1").CurrentRegion.Rows.Count
- str = Range("A" & i)
- If InStr(str, "、") = 0 Then
- Range("A" & i) = Format(Replace(Left(str, InStr(str, "日") - 1), "月", "-"), "yyyy年m月d日")
- Range("B" & i) = Format(Mid(str, InStr(str, ":") + 1), "yyyy年m月d日")
- Else
- Range("A" & i) = Format(Replace(Left(str, InStr(str, "日") - 1), "月", "-"), "yyyy年m月d日")
- Range("B" & i) = Format(Mid(Mid(str, InStr(str, ":") + 1), 1, InStr(Mid(str, InStr(str, ":") + 1), "、") - 1), "yyyy年m月d日")
- Range("C" & i) = Format(Mid(str, InStr(str, "、") + 1), "yyyy年m月d日")
- End If
- Next
- .Quit
- End With: Set IE = Nothing
- Application.ScreenUpdating = True
- Range("A1").CurrentRegion.Select: MsgBox "日期已更新", vbInformation, "VBA"
- End Sub
- Function IEWait(ByRef objIE As Object)
- Do While objIE.Busy = True Or objIE.readyState <> 4
- DoEvents
- Loop
- End Function
复制代码
养护日期_v1.2.xlsm.zip
(15.8 KB, 下载次数: 2)
|
|