使用 Excel VBA 自动获取网站图像 URL

问题描述

我有几个用于列出属性列表的网站,我想从中获取图像并使用 VBA 自动将它们导入 excel 单元格中,但我想我首先需要获取所有图像 URL,以便单独的程序获取图像。

>

我目前正在使用以下程序:

Sub scrapeimageurls()

Dim website as string
Dim IE As InternetExplorer
Dim html As HTMLDocument
Dim ElementCol As Object,Link As Object
Dim erow As Long

Application.ScreenUpdating = False

website = "https://ss.ge/ka/udzravi-qoneba/iyideba-4-otaxiani-bina-saburtaloze-3872071"

Set IE = New InternetExplorer

IE.Visible = False

IE.navigate website

do while IE.readyState <> READYSTATE_COMPLETE
Application.StatusBar = "Trying to go to website…"
Loop

Set html = IE.document
Set ElementCol = html.getElementsByTagName("img")

For Each Link In ElementCol
erow = Worksheets("sheet1").Cells(Rows.Count,1).End(xlUp).Offset(1,0).Row
Cells(erow,1).Value = Link.src

Next

End Sub

但是这段代码为网站上的所有徽标和内容带来了所有不必要的 URL,而我只想获取属性本身的图像的 URL。还有其他方法可以获取这些特定网址吗?

我想从中获取这些数据的网站(程序中使用的网站除外)如下:

  1. https://www.myhome.ge/ka/pr/11377747/iyideba-Zveli-ashenebuli-bina-vakeshi-wyneTis-qucha-3-oTaxiani
  2. https://livo.ge/udzravi-qoneba/iyideba-bina/iyideba-5-otaxiani-bina-saburtaloze-349298
  3. https://gethome.ge/udzravi-koneba/75955-iqideba-2-otakhiani-bina
  4. https://www.myclient.ge/detail?id=61352
  5. https://www.makler.ge/ka/ad/iyideba-3-othaxiani-bina-vakeshi-20000401
  6. https://area.ge/ka/search?listingId=236146

此外,这是在上一个类似这样的问题中与我共享的另一个过程,但这仅适用于代码本身中的网站,而不适用于其他网站。

Public Sub ImageLinks()

Dim ie As SHDocVw.InternetExplorer

Set ie = New SHDocVw.InternetExplorer

With ie

    .Visible = True
    .Navigate2 "https://ss.ge/ka/udzravi-qoneba/iyideba-4-otaxiani-bina-saburtaloze-3872071"
    
    While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
    
    With .Document.querySelectorAll(".OrdinaryContainer > img")
    
        Dim i As Long
        
        For i = 1 To .length
        
            ActiveSheet.Cells(i,1) = .Item(i - 1).src
        
        Next
    
    End With
    
    .Quit
End With

结束子

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)