我在刷新網頁時頗爲陌生,但我正在掌握它。我已經成功地獲得成功從網頁數據與follwing命令:如果元素存在,使用Excel VBA獲得web元素,如果不存在,則跳過
sht.Range("b" & RowCount).Value = .document.getElementById("PriceLabel").getElementsByTagName("span")(3).innerText
sht.Range("c" & RowCount).Value = .document.getElementById("QuantityInput").Value
我challange是不是我搜索的所有網頁有這些元素,所以腳本運行時錯誤424停止 - 所需的對象。
我試過一個On Error GoTo命令,但那隻適用於第一個事件,然後停在第二個網頁上,缺少的元素。
該代碼是:
Next_sku:
Do
RowCount = RowCount + 1
SKU = sht.Range("a" & RowCount).Value
With ie
.Visible = False
.navigate "http://www.staples.no/search?keywords=" & SKU
Do While .Busy Or _
.readyState <> 4
DoEvents
Loop
sht.Range("b" & RowCount).Value = .document.getElementById("PriceLabel").getElementsByTagName("span")(3).innerText
sht.Range("c" & RowCount).Value = .document.getElementById("QuantityInput").Value
On Error GoTo Next_sku
End With
Loop While sht.Range("a" & RowCount + 1).Value <> ""
任何人可以幫助我一個代碼,要麼返回一個空的結果,手動輸入如f.eks「不存在」 OG乾脆直接跳到下一個命令如果元素不存在,則返回行。最重要的是腳本不停止。
感謝:-)