从网站链接名称获取特定的URL(使用VBA) [英] Get the specific URL from the website link name (using VBA)

查看:252
本文介绍了从网站链接名称获取特定的URL(使用VBA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我发现下面的代码也在这里...但是这个结果所有的链接复制到表....如果我只想从特定的链接名称复制URL怎么办?请帮我代码例如下面的代码...我想要这个链接名称入门Excel VBA - 我的程序员的URL。应在单元格A1中生成一个URL http:// www .i-programmer.info / ebooks / automating-excel / 1264-getting-started.html
另请参见图像...提前谢谢!!!

Hello I found the below code also here...But this results all links copy into sheet....What if I want only to copy the URL from specific link name? Please help me code. For example with below code...I want the URL from this link name "Getting started with Excel VBA - I Programmer". Should result a URL in cell A1 "http://www.i-programmer.info/ebooks/automating-excel/1264-getting-started.html" See the image also...Thanks in advance!!!

Sub webpage()

    Dim internet As Object
    Dim internetdata As Object
    Dim div_result As Object
    Dim header_links As Object
    Dim link As Object
    Dim URL As String

    Set internet = CreateObject("InternetExplorer.Application")
    internet.Visible = True

    URL = "https://www.google.co.in/search?q=how+to+program+in+vba"
    internet.Navigate URL

    Do Until internet.ReadyState >= 4
        DoEvents
    Loop

    Application.Wait Now + TimeSerial(0, 0, 5)

    Set internetdata = internet.Document
    Set div_result = internetdata.getelementbyid("res")


    Set header_links = div_result.getelementsbytagname("h3")

    For Each h In header_links
        Set link = h.ChildNodes.Item(0)
        Cells(Range("A" & Rows.Count).End(xlUp).Row + 1, 1) = link.href
    Next

    MsgBox "done"
End Sub

输入图像描述这里

推荐答案

您可以检查 innerText 属性

For Each h In header_links
    If h.innerText = "Getting started with Excel VBA - I Programmer" Then
        Set link = h.ChildNodes.Item(0)
        Cells(Range("A" & Rows.Count).End(xlUp).Row + 1, 1) = link.href
    End If
Next

这篇关于从网站链接名称获取特定的URL(使用VBA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆