1-1 Chrome F12
1-2 ②
1-3 ③
2 getElementsByClassName
※上図参照
Price = document.getElementsByClassName('tm-price')ではなく[0].innerText追加して取得する。
<正しい>
Price = document.getElementsByClassName('tm-price')[0].innerText
3 getElementsByTagName (getAttribute)
function taobaoEx_getOptionsContent() { var optStr = '' var v_dl = document.getElementsByClassName('tb-sku')[0].getElementsByTagName('dl') //for (var i = 0; i < v_dl.length-2; i++) for (var i = 0; i < 2; i++) { optStr += v_dl[i].getElementsByTagName('dt')[0].innerHTML optStr += ' ' v_li = v_dl[i].getElementsByTagName('dd')[0].getElementsByTagName('ul')[0].getElementsByTagName('li') //console.log(v_li) for (var j = 0; j < v_li.length; j++) { console.log(v_li[j]) if (v_li[j].innerText != '') { optStr += (v_li[j].innerText).replace(/\r?\n/g, " ") } else { optStr += (v_li[j].getElementsByTagName('a')[0].getAttribute('title')).replace(/ /g, '-') } optStr += ' ' //console.log(optStr) } //optStr += '\r' } return optStr }