我正在尝试检索Excel VBA中的a href属性和文本值

我正在尝试检索Excel VBA中的a href属性和文本值,vba,excel,Vba,Excel,以下JAVA代码有助于获得我的答案: Elements aElement = doc.getElementsByTag("a"); for (Element e:aElement) { if(e.attr("href").contains("director/")) { companyInfo.setName(e.text().trim()); break; } } 我正在尝试从以下链接检索控制器

以下JAVA代码有助于获得我的答案:

 Elements aElement = doc.getElementsByTag("a");
    for (Element e:aElement) {
        if(e.attr("href").contains("director/")) {
            companyInfo.setName(e.text().trim());
            break;
        }
    }
我正在尝试从以下链接检索控制器名称:

我试图在HTML中搜索文本“/director/*”,然后检索director名称并将其发布到Excel:

这是我的密码:

Set H3 = HTMLdoc.getElementsByTagName("a")

     For Each Line In H3
        If Line.innerText Like "*/director/*" Then
            temp = Line.innerText
            Sheet2.Range("C" & x).Value = temp
         End If
     Next

您似乎混淆了锚元素的
.href
.innerText
属性

 For Each Line In H3
    If cbool(instr(1, Line.href, "/director/", vbtextcompare)) Then
        Sheet2.Range("C" & x).Value = Line.innerText
        x = x + 1
     End If
 Next

您似乎混淆了锚元素的
.href
.innerText
属性

 For Each Line In H3
    If cbool(instr(1, Line.href, "/director/", vbtextcompare)) Then
        Sheet2.Range("C" & x).Value = Line.innerText
        x = x + 1
     End If
 Next

@RyanWildry-查看链接页面上的实际HTML,我认为OP需要在
.href
中查找
/director/
,而不是
.innerText
@RyanWildry-查看链接页面上的实际HTML,我相信OP需要在
.href
中查找
/director/
,不是
.innerText
。您不需要cBool。如果位置>0,inStr将返回为true。是的,CBool将0和>0变为False和true。不需要它。如果instr(1,Line.href,“/director/”,vbtextcompare)>0,那么我可以使用
,但我决定这样做。你也不需要>0。你不需要cBool。如果位置>0,inStr将返回为true。是的,CBool将0和>0变为False和true。不需要它。如果instr(1,Line.href,“/director/”,vbtextcompare)>0,那么我可以使用
,但我决定这样做。你也不需要>0。