【问题标题】:Extract text from a DOM element in javascript casperjs从javascript casperjs中的DOM元素中提取文本
【发布时间】:2020-02-07 03:56:16
【问题描述】:
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"]'));

}

有时候 span 之前有 2 个 div 而不是 3 个 div。我需要始终从 div.ma-AdCardMyAds:nth-child('+1+') 开始达到 span[class="ma-AdCard-price"]

只有 div.one > div.three

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"]')

【问题讨论】:

    标签: javascript casperjs


    【解决方案1】:

    你可以试试这个:

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

    如果div.onediv.two 始终存在,请使用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2014-11-17
      • 1970-01-01
      • 2020-10-24
      • 2020-09-04
      • 1970-01-01
      • 2018-08-09
      相关资源
      最近更新 更多