我想从网站上获取itemprop微数据并将每个微数据放入excel表格的单元格中。
<li>Item Num: <span itemprop="productID">123ABC-200</span>
</li>
<li>ManufacturerNum: <span itemprop="model">ABC123</span>
</li>
我将地址存储在一列中,我正在尝试打开IE,导航到网站,抓取数据,然后将其扔到另一个单元格中。
Sub scrape()
Dim i As Integer
lastrow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lastrow
Set wb = CreateObject("internetExplorer.Application")
sURL = Cells(i, 1)
wb.navigate sURL
wb.Visible = True
While wb.Busy
DoEvents
Wend
'HTML document
Set doc = wb.document
Cells(i, 2) = doc.Title
On Error GoTo err_clear
Dim el As Object
elem = doc.GetElementsByTagName("span")
atts = elem.getAttribute("itemprop")
For Each el In atts
Cells(i, 3).Value = Cells(i, 3).Value & ", " & el.innerText
Next el
err_clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
wb.Quit
Range(Cells(i, 1), Cells(i, 3)).Columns.AutoFit
Next i
End Sub
我什么都没回来。如果我只搜索跨度,我可以将它们全部拉入。我没有成功从任何html元素中提取任何属性。