Yes it is possible, please take a look at the code below it will give you the basic idea. You can change ul to div and add some logic to match your needs.
$menu_name="primary";
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
$menu_list="<ul id="menu-" . $menu_name . '">';
foreach ( (array) $menu_items as $key => $menu_item ) {
$title = $menu_item->title;
$url = $menu_item->url;
$menu_list .= '<li><a href="' . $url . '">' . $title . '</a></li>';
}
$menu_list .= '</ul>';
Here’s a good reference : https://developer.wordpress.org/reference/functions/wp_get_nav_menu_items/