代码之家  ›  专栏  ›  技术社区  ›  Javier Sega

从javascript casperjs中的DOM元素提取文本

  •  0
  • Javier Sega  · 技术社区  · 5 年前
    for(var i=0; i < 20; i++) { 
    
    this.fetchText('div.ma-AdCardMyAds:nth-child('+i+') > div.one > div.two > div.three > span[class="ma-AdCard-price"]'));
    
    }
    

    有些情况下,在跨度前有2个div而不是3个div。我需要始终从div.ma-AdCardMyAds:nth child('+1+')开始达到span[class=“ma AdCard price”]

    仅第一部分第三部分

    this.fetchText('div.ma-AdCardMyAds:nth-child('+i+') > div.one > div.three > span[class="ma-AdCard-price"]'));
    
    

    不起作用

    this.fetchText('div.ma-AdCardMyAds:nth-child('+i+') > span[class="ma-AdCard-price"]')
    
    1 回复  |  直到 5 年前
        1
  •  1
  •   thanhdx    5 年前

    你可以试试这个:

    this.fetchText('div.ma-AdCardMyAds:nth-child('+i+') span[class="ma-AdCard-price"]')
    

    div.one div.two

    this.fetchText('div.ma-AdCardMyAds:nth-child('+i+') > div.one > div.two span[class="ma-AdCard-price"]')