크롤링에서요 옵션 stock 갯수가 밑에 형식으로 되어있을때 어떻게 추출해야할까요??
본문
$option_dom = $dom -> find('ul.mi-select-option',0);
if($option_dom) $option_dom = $option_dom -> find("li");
//if($option_dom and !is_array($option_dom)) foreach($option_dom as $option_data) { 배열값을 추출못함
$option_cnt = 0;
if(is_array($option_dom)) foreach($option_dom as $option_data) {
if($option_cnt == -1 ){ //상품옵션 0 index 값이 없고 옵션만 나올때
$option_title_value = trim($option_data -> plaintext);
$option_title[] = $option_title_value;
}
else {
$option_name = trim($option_data -> value);
// $option_stx = explode(" ", $option_stx);
//print_m($option_stx[0]);
$option_list[$option_title_value][] = $option_name;
$option_info_key = $option_name;
$option_stock = trim($option_data -> getAttribute('data-stock'));
//echo "<xmp>".$option_data."</xmp>";
//$option_stock=trim($option_name -> getAttribute('data-stock'));
$option_sku = $_SKU."_".str_replace(" ","_",$option_name);
$option_info[$option_info_key]['SKU'] = $option_sku;
$option_info[$option_info_key]['Stock'] = $option_stock;
$option_info[$option_info_key]['Price'] = $_Price;
$option_info[$option_info_key]['Currency'] = $_Currency;
$option_info[$option_info_key]['Image'] = $_Image;
$option_info[$option_info_key]['ImageSet'] = $_ImageSet;
}
$option_cnt++;
}
답변 1
1. 올려주신 이미지를 봤을때 data-stock getAttribute 를 가져오는데 해당 값이 안보입니다
2. 해당 값이 있다고 가정했을때 option_stock 변수에는 data-stock 값이 들어가니까 나올꺼 같은데요
근데 코드가 보면 실행이 안될꺼 같은데요