2016-07-13 4 views
0

ここに私のコードです。それは、Amazonの詳細ページから「アイテムモデル番号」を引き出します。これは、詳細ページの箇条書きの点にある「品目モデル番号」を見つけ、その隣の番号を抽出するために書かれています。正しい箇条書きと情報を取得するまで、製品の箇条書きをループするようにWebスクレイピングコードを変更するにはどうすればよいですか?

問題は、アイテムモデル番号を持つページから「アイテムモデル番号」を取得できないことがあるということです。

ここでコード

Sub Get_ITEM_CODE(ie As Object) 
    Dim WB As Workbook 
    Dim WS As Worksheet 
    Dim y As String 
    Dim AmUrl As String 
    AmUrl = ActiveCell.Value 
    ''Set WB = Workbooks.Add 

    Set WS = Sheets("Extract Item COde") 
    ie.Navigate AmUrl 
    Application.Wait (Now + TimeValue("00:00:02")) 
    Do While ie.readyState <> 4: Loop 
    On Error Resume Next 

    y = ie.document.getElementById("productDetails_detailBullets_sections1").innerText 

    WS.Range("A1").Value = y 

    SplitTextItemCode 
    AddtoListItemCode 

End Sub 

ここでは、コードが正しくその仕事をしていませんHTMLの文字列です。ここで

<div id="detailBullets" class="feature" data-feature-name="detailBullets"> 

<div id="detailBulletsWrapper_feature_div" data-feature-name="detailBullets" data-template-name="detailBullets" class="a-section a-spacing-none feature"> 
    <div id="detailBullets_feature_div"> 

URL to webpage

はコードHTMLの文字列です。仕事をしなかった:

<div id="detailBullets" class="feature" data-feature-name="detailBullets"> 

<div id="detailBulletsWrapper_feature_div" data-feature-name="detailBullets" data-template-name="detailBullets" class="a-section a-spacing-none feature"> 
    <div id="detailBullets_feature_div"> 

URL to Web Page

答えて

0

これを試すと、その要素idの下にあるすべての "li"項目がループします。それから、 "Item model number:"のテキストを置き換えたり削除したりして、見ている製品のクリーンなモデル番号を残します。

Dim Cnt As Variant 
Dim oCell As Object 
Cnt = 0 
With ie.Document.body.all.Item("detailBulletsWrapper_feature_div").all 
    For Each oCell In .tags("li") 
     If InStr(oCell.innerText, "Item model number:") > 0 Then 
      ModelNum = oCell.innerText 
      ModelNum = VBA.Replace(ModelNum, "Item model number: ", "") 
      Debug.Print ModelNum 
     Exit For 
     End If 
    Cnt = Cnt + 1 
Next oCell 
End With 
Set oCell = Nothing 
    End Sub 
+0

Excelが変数として定義する "CNT" と "oCell" が必要、それ以外のコードは正常に実行されていません。 –

+0

正しいです、cntは変数として定義する必要があります。 Ocellはオブジェクトとして定義する必要があります... – BigElittles

関連する問題