def __parse_single_restaurant(li): """ 下記の形式のHTMLをParseする。 <li> <a href='****' title='****の待ち時間'> <ul> <li class='photo'><img data-src='****' width='64' height='64' class='lozad' alt='***'></li> <li class='desc'> <h4>レストラン名称</h4> <p>運営ステータス<br> <span class='runtime'>11:00-17:45</span></p> </li> </ul> </a> </li> """ restaurant = Restaurant() if elem_desc := li.find(class_='desc'): # レストラン名称 restaurant.name = elem_desc.find('h4').text for child in elem_desc.children: if not child: continue if not child.text: continue # 中止フラグ if "中止" in child.text: restaurant.disable_flag = True # ステータス・営業時間 if "-" in child.text and ":" in child.text: splited_result = child.text.split(" ") if len(splited_result) == 2: restaurant.status, start_end_time = child.text.split( " ") restaurant.start_time, restaurant.end_time = start_end_time.split( "-") else: restaurant.status = child.text.strip() # リアルタイム待ち時間 if elem_time := li.find(class_='time'): wait_time_str = elem_time.find('p').text.strip('待ち時間').strip( "分") # 時間に幅がある場合は最も大きい値をとる if "-" in wait_time_str: wait_time_min, wait_time_max = wait_time_str.split("-") wait_time_str = wait_time_max if wait_time_max != "" else wait_time_min if wait_time_str.strip() != "": restaurant.wait_time = int(wait_time_str)