从网站上抓取数据

时间:2017-07-20 13:57:59

标签: vb.net vba

如何使用vb获得反馈分数?我的代码仅适用于getelementbyid。

<div class="si-content ">
<h2 class="si-ttl si-trs-ttl">
   Seller information
</h2>
<div class="bdg-78">
<div class="mbg">
   <a href="http://www.ebay.co.uk/usr/userid5.2.17?_trksid=p2047675.l2559" 
      aria-label="Member ID:&nbsp;userid5.2.17" id="mbgLink"> <span class="mbg-
      nw">userid5.2.17</span></a>
   <span class="mbg-l">
   (<a href="http://feedback.ebay.co.uk/ws/eBayISAPI.dll? ViewFeedback&userid=userid5.2.17&iid=122504533088&ssPageName=VIP:feedback&ftab=F
      eedbackAsSeller&rt=nc&_trksid=p2047675.l2560" title="Feedback score: 
      15658">15658</a>
   <img 
      alt="Feedback score: 15658"
      title="Feedback score: 15658"
      src="http://ir.ebaystatic.com/pictures/aw/pics/star-11.gif"">)</span>
</div>

1 个答案:

答案 0 :(得分:0)

您可以使用getElementsByTagName循环遍历每个链接。然后,您可以使用getAttribute检查每个链接的title属性。这是一个例子......

'Requires a reference (VBE > Tools > Reference) to
'the Microsoft HTML Object Library
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim HTMLLink As MSHTML.IHTMLAnchorElement

HTMLDoc.body.innerHTML = Range("A1").Value

For Each HTMLLink In HTMLDoc.getElementsByTagName("a")
    If Left(HTMLLink.getAttribute("title"), 15) = "Feedback score:" Then
        MsgBox HTMLLink.innerText, vbInformation
        Exit For
    End If
Next HTMLLink
相关问题