Excel VBA查找网页图像并将其导入到excel中

目前,我正在尝试search一个打开的网页上的一些PNG图像,并将其导入到我的Excel工作簿的选项卡中的不同单元格中。

我现有的macros浏览一个网页,指定什么图片将显示,有多less。

我正在试图写一个macros,在这一点上search打开的网页,并将图像导入excel。

每次程序运行时,图像的数量都是不可知的。 但是每个图像都在下面的html代码中:

img src="/files/exercises/31a_3 - trunk stability rotation kneex flexed.still002.194x146.png" title="Step 2" 

而文件名称将会改变。 我正在寻找标题=“第2步”的所有图像

并将所有这些图像导入到excel中。 目前,我可以通过以下代码成功findurl:

 max = 100 For i = 0 To max For Each Elem In ie.Document.getElementsByTagName("img") If ie.Document.getElementsByTagName("img").Item(i).getAttribute("title") = "Step 2" Then Worksheets("Sheet4").Range("A1") = "http://functionalmovement.com" & ie.Document.getElementsByTagName("img").Item(i).getAttribute("src") Exit For Exit For End If Next Next End Sub 

问题:

  1. 我怎样才能search整个页面,并find第一个发现在一个特定的细胞,第二个发现放在另一个单元格,等到没有更多的发现。

  2. 有没有办法让图像本身出现现在,每个图像的完整的url是已知的。

find我正在寻找的东西。 此代码searchtitle =“Step 1”的图像。 然后我下载这些图像。

 Sub findimageA() Dim strURL As String Dim ie As Object Dim Elem Dim X Set ie = CreateObject("InternetExplorer.Application") strURL = "http://blahblah" ie.Navigate strURL ie.Visible = True Do While (ie.Busy Or ie.READYSTATE <> 4) DoEvents Loop For Each Elem In ie.Document.getElementsByTagName("img") If Elem.getAttribute("title") = "Step 1" Then Select Case X Case Is = 0 pic1aURL = "http://functionalmovement.com" & Elem.getAttribute("src") pic1aName = Elem.getAttribute("src") pic1aName1 = Replace(pic1aName, "/files/exercises/", "") Case Is = 1 pic2aURL = "http://functionalmovement.com" & Elem.getAttribute("src") pic2aName = Elem.getAttribute("src") pic2aName1 = Replace(pic2aName, "/files/exercises/", "") Case Is = 2 End Select X = X + 1 End If Next If Not IsEmpty(picaName) Then DownloadFile End If End Sub