我使用VBA从具有多个无序列表条目的网页中提取,如下所示: 从HTML链接中提取文本与VBA
我能够获得“ICD-10-CM S82.311D”值,但我需要“环面骨折...”值的链接。我该怎么做呢?
这里是我的代码:
公共功能convertICD(BYVAL icdCode作为字符串)
Dim ie As Variant
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
ie.navigate "www.icd10data.com/Convert/" & icdCode
Do
DoEvents
Loop Until ie.ReadyState = 4
Dim DOC As HTMLDocument
Set DOC = ie.Document
Dim idx As Integer
Dim answer As String
answer = ""
Dim links As Variant
Dim lnk As Variant
Dim cnt As Integer
cnt = 0
Set links = DOC.getElementsByTagName("a")
For Each lnk In links
cnt = cnt + 1
If cnt > 8 Then 'Ignore the first 8
answer = answer + lnk.innerText + vbCrLf
End If
Next
convertICD = answer
Set ie = Nothing
端功能
我敢肯定,一个呻吟会从最了解如何做到这一点的人那里上去,但如果你没有其他答案......你可以搜索网页文本中的字符串,如“转换为约”(或一些字符串,总是会返回),然后去第8'>'和你寻求的字符串将从第8 +1开始,并转到下一个'<' - 1. –
getElementsByClassName(“img externalIcon”)可能工作 – justkrys
谢谢你们。挖入“查看源代码”并尝试通过TagName“li”获取。获取内部文本给了我我的代码和细节,然后我只需要解析它们。可能有更好的方法,但这足以满足我的需求。再次,谢谢。 – PKatona