如何解决使用 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。还有其他方法可以获取这些特定网址吗?
我想从中获取这些数据的网站(程序中使用的网站除外)如下:
- https://www.myhome.ge/ka/pr/11377747/iyideba-Zveli-ashenebuli-bina-vakeshi-wyneTis-qucha-3-oTaxiani
- https://livo.ge/udzravi-qoneba/iyideba-bina/iyideba-5-otaxiani-bina-saburtaloze-349298
- https://gethome.ge/udzravi-koneba/75955-iqideba-2-otakhiani-bina
- https://www.myclient.ge/detail?id=61352
- https://www.makler.ge/ka/ad/iyideba-3-othaxiani-bina-vakeshi-20000401
- 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 举报,一经查实,本站将立刻删除。