-2

我正在尝试从此数据中获取所有 http 链接。

<a class="l-link-w clearfix" data-target-weblink target="_blank" href='http://www.havenswift-hosting.co.uk/clients/link.php?id=17' data-company-item="visitwebsite" data-omniture="WL">
<a class="l-link-w clearfix" data-target-weblink target="_blank" href='https://www.rathosting.com/' data-company-item="visitwebsite" data-omniture="WL">
<a class="l-link-w clearfix" data-target-weblink target="_blank" href='http://www.glxwebhosting.co.uk/' data-company-item="visitwebsite" data-omniture="WL">
<a class="l-link-w clearfix" data-target-weblink target="_blank" href='http://www.immersivemedia.co.uk' data-company-item="visitwebsite" data-omniture="WL">
4

1 回答 1

0

假设您上面的来源在 A1 中:

Dim source As String
source = Range("A1").Value

i = InStr(1, source, "http", vbBinaryCompare)
e = InStr(1, source, "data-company", vbBinaryCompare)

link = Mid(source, i, (e - i - 1))
MsgBox (link)

对于多个值,您可以创建一个读取所有行的循环......只需将一些代码替换为上面的 Range("A1").Value。像这样的东西:

      Dim numRows As Integer

      'Replace the A1 with the location where you want your data
      Dim sourceData As Range
      Set sourceData = Range("A1")

      'Replace the A15 to where you want the data
      Dim destData As Range
      Set destData = Range("A15")

      'Set this to the number of rows in the source data
      numRows = 4

      For k = 1 To numRows
        Dim source As String

        'Replace A1 with the cell of the first line of data
        source = sourceData.Offset(k, 0).Value

        i = InStr(1, source, "http", vbBinaryCompare)
        e = InStr(1, source, "data-company", vbBinaryCompare)

        If ((i > 0) And (e > 0)) Then
            link = Mid(source, i, (e - i - 1))
            destData.Offset(k, 0).Value = link
        End If


      Next k
于 2013-10-19T01:00:45.620 回答