Html 图片标签,
Html tag of picture,
我想解析来自亚马逊的图片 link 的 url,但由于我是新手,所以我不确定它的标签名。
我有一个 vba 代码使用
设置 myLinks = html.getElementsByTagName("img")
解析,但是找不到图片link.
你能帮帮我吗?
谢谢。
代码:
Sub GetAboutUsLinks2()
'First define all the variables
Dim ie As Object
Dim html As Object
Dim myLinks As Object
Dim myLink As Object
Dim result As String
Dim myURL As String
Dim LastRow As Integer
Set ie = CreateObject("InternetExplorer.Application")
LastRow = Sheet1.Cells(Rows.Count, "a").End(xlUp).Row
For i = 2 To LastRow
myURL = Sheet1.Cells(i, 1).Value
ie.navigate myURL
ie.Visible = True
While ie.readyState <> 4
DoEvents
Wend
result = ie.document.body.innerHTML
Set html = CreateObject("htmlfile")
html.body.innerHTML = result
Set myLinks = html.getElementsByTagName("img").
For Each myLink In myLinks
If Right$(myLink, 4) = ".jpg" Then
Sheet1.Cells(i, "B").Value = myLinks
Else
Sheet1.Cells(i, "B").Value = "Not found"
End If
Next myLink
If i = LastRow Then
ie.Quit
End If
Next i
End Sub
这对我有用。无需从 IE 获取 HTML 即可进行任何解析:您可以直接使用加载的页面。
Sub GetAboutUsLinks2()
'First define all the variables
Dim ie As Object
Dim myPic As Object
Dim myURL As String
Dim LastRow As Long, i As Long
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
LastRow = Sheet1.Cells(Rows.Count, "a").End(xlUp).Row
For i = 2 To LastRow
myURL = Sheet1.Cells(i, 1).Value
ie.navigate myURL
While ie.busy Or ie.readyState <> 4
DoEvents
Wend
Set myPic = ie.document.getElementById("landingImage")
If Not myPic Is Nothing Then
Sheet1.Cells(i, "B").Value = myPic.src
Else
Sheet1.Cells(i, "B").Value = "Not found"
End If
Next i
ie.Quit
Set ie = Nothing
End Sub
我想解析来自亚马逊的图片 link 的 url,但由于我是新手,所以我不确定它的标签名。
我有一个 vba 代码使用 设置 myLinks = html.getElementsByTagName("img") 解析,但是找不到图片link.
你能帮帮我吗?
谢谢。
代码:
Sub GetAboutUsLinks2()
'First define all the variables
Dim ie As Object
Dim html As Object
Dim myLinks As Object
Dim myLink As Object
Dim result As String
Dim myURL As String
Dim LastRow As Integer
Set ie = CreateObject("InternetExplorer.Application")
LastRow = Sheet1.Cells(Rows.Count, "a").End(xlUp).Row
For i = 2 To LastRow
myURL = Sheet1.Cells(i, 1).Value
ie.navigate myURL
ie.Visible = True
While ie.readyState <> 4
DoEvents
Wend
result = ie.document.body.innerHTML
Set html = CreateObject("htmlfile")
html.body.innerHTML = result
Set myLinks = html.getElementsByTagName("img").
For Each myLink In myLinks
If Right$(myLink, 4) = ".jpg" Then
Sheet1.Cells(i, "B").Value = myLinks
Else
Sheet1.Cells(i, "B").Value = "Not found"
End If
Next myLink
If i = LastRow Then
ie.Quit
End If
Next i
End Sub
这对我有用。无需从 IE 获取 HTML 即可进行任何解析:您可以直接使用加载的页面。
Sub GetAboutUsLinks2()
'First define all the variables
Dim ie As Object
Dim myPic As Object
Dim myURL As String
Dim LastRow As Long, i As Long
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
LastRow = Sheet1.Cells(Rows.Count, "a").End(xlUp).Row
For i = 2 To LastRow
myURL = Sheet1.Cells(i, 1).Value
ie.navigate myURL
While ie.busy Or ie.readyState <> 4
DoEvents
Wend
Set myPic = ie.document.getElementById("landingImage")
If Not myPic Is Nothing Then
Sheet1.Cells(i, "B").Value = myPic.src
Else
Sheet1.Cells(i, "B").Value = "Not found"
End If
Next i
ie.Quit
Set ie = Nothing
End Sub