Parsing HTML - Only showing one item not the list - xpath

protected async override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string htmlPage = "";
using (var client = new HttpClient())
{
// htmlPage = await client.GetStringAsync("http://m.buses.co.uk/stop.aspx?stopid=6884");
//htmlPage = await client.GetStringAsync("http://www.imdb.com/movies-in-theaters/");
htmlPage = await client.GetStringAsync("http://m.buses.co.uk/destinations.aspx");
}
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(htmlPage);
List<Movie> movies = new List<Movie>();
foreach (var div in htmlDocument.DocumentNode.SelectNodes("//div[starts-with(#class, 'menu')]"))
{
Movie newMovie = new Movie();
// newMovie.Cover = div.SelectSingleNode(".//div[#class='image']//img").Attributes["src"].Value;
// newMovie.Title = div.SelectSingleNode(".//h4[#itemprop='name']").InnerText.Trim();
// newMovie.Summary = div.SelectSingleNode(".//div[#class='outline']").InnerText.Trim();
// newMovie.Summary = div.SelectSingleNode(".//div[#class='services']").InnerText.Trim();
newMovie.Summary = div.SelectSingleNode(".//a[starts-with(#href, 'place.aspx')]").InnerText.Trim();
movies.Add(newMovie);
}
lstMovies.ItemsSource = movies;
}
I am trying to get the list of Popular Destinations, the Names of the places, below is the part which I am interested in. I am able with the code above to get the first place - Amex Stadium. But it's not displaying anymore than that.
<div class="menu">
<ul>
<li>
<a href="place.aspx?placeid=1154">
Amex Stadium
</a>
</li>
<li>
<a href="place.aspx?placeid=1136">
Brighton Marina
</a>
</li>
<li>
<a href="place.aspx?placeid=907">
Brighton Station
</a>
</li>
<li>
<a href="place.aspx?placeid=910">
Brighton University Moulsecoomb
</a>
</li>
<li>
<a href="place.aspx?placeid=916">
Churchill Square
</a>
</li>
<li>
<a href="place.aspx?placeid=918">
Coldean
</a>
</li>
<li>
<a href="place.aspx?placeid=924">
County Hospital
</a>
</li>
<li>
<a href="place.aspx?placeid=943">
Eastbourne
</a>
</li>
<li>
<a href="place.aspx?placeid=957">
George Street Hove
</a>
</li>
<li>
<a href="place.aspx?placeid=965">
Hangleton
</a>
</li>
<li>
<a href="place.aspx?placeid=972">
Hollingbury
</a>
</li>
<li>
<a href="place.aspx?placeid=993">
Lewes
</a>
</li>
<li>
<a href="place.aspx?placeid=997">
Longhill School
</a>
</li>
<li>
<a href="place.aspx?placeid=1006">
Mile Oak
</a>
</li>
<li>
<a href="place.aspx?placeid=1011">
Newhaven
</a>
</li>
<li>
<a href="place.aspx?placeid=1134">
North Street
</a>
</li>
<li>
<a href="place.aspx?placeid=1020">
Old Steine
</a>
</li>
<li>
<a href="place.aspx?placeid=1026">
Patcham
</a>
</li>
<li>
<a href="place.aspx?placeid=1028">
Peacehaven
</a>
</li>
<li>
<a href="place.aspx?placeid=1035">
Portslade Station
</a>
</li>
<li>
<a href="place.aspx?placeid=1042">
Queens Park
</a>
</li>
<li>
<a href="place.aspx?placeid=1047">
Rottingdean
</a>
</li>
<li>
<a href="place.aspx?placeid=1057">
Seaford
</a>
</li>
<li>
<a href="place.aspx?placeid=1062">
Shoreham
</a>
</li>
<li>
<a href="place.aspx?placeid=1135">
St Peter's Church
</a>
</li>
<li>
<a href="place.aspx?placeid=1074">
Steyning
</a>
</li>
<li>
<a href="place.aspx?placeid=1076">
Sussex University
</a>
</li>
<li>
<a href="place.aspx?placeid=1080">
Tunbridge Wells
</a>
</li>
<li>
<a href="place.aspx?placeid=1082">
Uckfield
</a>
</li>
<li>
<a href="place.aspx?placeid=1091">
Westdene
</a>
</li>
<li>
<a href="place.aspx?placeid=1092">
Whitehawk
</a>
</li>
<li>
<a href="place.aspx?placeid=1095">
Woodingdean
</a>
</li>
</ul>
</div>

Your selections is wrong. The statement
SelectNodes("//div[starts-with(#class, 'menu')]")
only selects <DIV class="menu"> and since there is only one such DIV you only get one place. You should change it to:
SelectNodes("//div[starts-with(#class, 'menu')]/ul/li")
and then use:
newMovie.Summary = div.SelectSingleNode("a[starts-with(#href, 'place.aspx')]").InnerText.Trim();
Notice, I removed .// from this latter selection.

Related

Drag and drop not working with cypress automated script

this is the application html with drag and drop content
<li>
<a class='place_video help_fields_controller_place_video' data-kind='stimuli' data-type='place_video' href='#'>
Place Video
<b></b>
</a>
</li>
<li>
<a class='place_photo help_fields_controller_place_photo' data-kind='stimuli' data-type='place_photo' href='#'>
Place Photo
<b></b>
</a>
</li>
<li>
<a class='place_file help_fields_controller_place_file' data-kind='stimuli' data-type='place_file' href='#'>
Place File
<b></b>
</a>
</li>
<li>
<a class='place_link help_fields_controller_place_link' data-kind='stimuli' data-type='place_link' href='#'>
Survey Link
<b></b>
</a>
</li>
</ul>
<br style='clear:left'>
</div>
</div>
<div id='follow'>
<div class='box collapsable activity_controls js_collectors' href='/fields/new'>
<h3 class='clearfix box_header'>
<div class='controls'>
</div>
<a action='collapse' class='collapse' href='#'></a>
<span class='help_activities_controller_collectors'>
Collectors
</span>
</h3>
<div class='content'>
<ul id='sortable_collectors'>
<li>
<a class='paragraph_text help_fields_controller_paragraph_text' data-kind='collector' data-type='paragraph_text' href='#'>
Paragraph Text
<b></b>
</a>
</li>
<li>
<a class='single_line_text help_fields_controller_single_line_text' data-kind='collector' data-type='single_line_text' href='#'>
Single Line Text
<b></b>
</a>
</li>
<li>
<a class='website help_fields_controller_website' data-kind='collector' data-type='website' href='#'>
Website
<b></b>
</a>
</li>
<li>
<a class='date help_fields_controller_date' data-kind='collector' data-type='date' href='#'>
Date
<b></b>
</a>
</li>
<li>
<a class='request_photo help_fields_controller_request_photo' data-kind='collector' data-type='request_photo' href='#'>
Request Photo
<b></b>
</a>
</li>
<li>
<a class='request_file help_fields_controller_request_file' data-kind='collector' data-type='request_file' href='#'>
Request File
<b></b>
</a>
</li>
<li>
<a class='request_video help_fields_controller_request_video' data-kind='collector' data-type='request_video' href='#'>
Request Video
<b></b>
</a>
</li>
<li>
<a class='single_choice help_fields_controller_single_choice' data-kind='collector' data-type='single_choice' href='#'>
Single Choice
<b></b>
</a>
</li>
<li>
<a class='multiple_choice help_fields_controller_multiple_choice' data-kind='collector' data-type='multiple_choice' href='#'>
Multiple Choice
<b></b>
</a>
</li>
<li>
<a class='drop_down help_fields_controller_drop_down' data-kind='collector' data-type='drop_down' href='#'>
Drop Down
<b></b>
</a>
</li>
<li>
<a class='time help_fields_controller_time' data-kind='collector' data-type='time' href='#'>
Time
<b></b>
</a>
</li>
<li>
<a class='number help_fields_controller_number' data-kind='collector' data-type='number' href='#'>
Number
<b></b>
</a>
</li>
<li id='location-collector'>
<a class='location help_fields_controller_location' data-kind='collector' data-type='location' href='#'>
Location
<b></b>
</a>
</li>
</ul>
<br style='clear: left'>
</div>
</div>
</div>
</div>
</td>
<td class='work_area'>
<div id='activity_fields'>
<input type="hidden" name="activity[form_attributes][id]" id="activity_form_attributes_id" />
<ul class='empty_sort_table' id='sortable'>
<li class='blank-slate'>
Build your activity by drag and dropping stimuli and collectors from the palette.
</li>
</ul>
</div>
</td>
</tr>
</table>
I would like to drag the instructional text and drop on the activity builder area and the cypress code for it
it('Activity Builder: Activity Library, Activity & Scheduling', () => {
const dataTransfer = new DataTransfer()
//Activity Scheduling
leftMenuNavigation.clickActivityScheduling()
cy.findByRole('heading', { name: /activities & scheduling/i }).should(
'be.visible'
)
//creating activity
cy.findByText(/^New Activity$/i)
.should('be.visible')
.parent()
.click()
cy.findByText(/activity/i, {
selector: '.goog-menuitem-content'
}).click({ force: true })
cy.findByRole('link', { name: /instructional text/i }).trigger(
'dragstart',
{
dataTransfer
}
)
cy.findByRole('cell', {
name: /build your activity by drag and dropping stimuli and collectors from the palette\.
/i
})
.findByRole('listitem')
.trigger('drop')
.trigger('dragend')
})
})
})

How to display just one menu in a dynamic menu

I hava a dynamic menu using VueJs and Laravel. It works fine.
But when I display one of them, all options are displayed.
The menu starts in foreach loop to check menu and assigned options.
Is there any way to restrict this?
My code is the next:
File sidebar.blade.php
<div class="sidebar">
<nav class="sidebar-nav">
<ul class="nav">
<li #click="menu=0" class="nav-item">
<a class="nav-link active" href="#"><i class="icon-speedometer"></i> Escritorio</a>
</li>
<li class="nav-title">
Menú de opciones
</li>
<li class="nav-item nav-dropdown">
#foreach($menus as $menu)
<a class="nav-link nav-dropdown-toggle" href="#"><i class="{{ $menu->icono_menu }}"></i>{{ $menu->nombre }}</a>
#foreach($permisos as $permiso)
#if($menu->id==$permiso->idmenu)
<ul class="nav-dropdown-items">
<li #click="menu={{ $permiso->codigo }}" class="nav-item">
<a class="nav-link" href="#"><i class="{{ $permiso->icono_opcion }}"></i> {{ $permiso->nombre }}</a>
</li>
</ul>
#endif
#endforeach
#endforeach
</li>
<li #click="menu=27" class="nav-item">
<a class="nav-link" href="#"><i class="icon-book-open"></i> Ayuda <span class="badge badge-danger">PDF</span></a>
</li>
<li #click="menu=28" class="nav-item">
<a class="nav-link" href="#"><i class="icon-info"></i> Acerca de...<span class="badge badge-info">IT</span></a>
</li>
</ul>
</nav>
<button class="sidebar-minimizer brand-minimizer" type="button"></button>
</div>

Set class on Parent and Sub-Menu in Laravel Bade View

I want to set m-menu__item--open class on parent menu <li> and m-menu__item--active class on sub-menu item <li> in my Laravel bade based on current page. Below is the HTML extracted from the bade template.
<li class="m-menu__item m-menu__item--open" aria-haspopup="true" m-menu-submenu-toggle="hover">
<a href="javascript:;" class="m-menu__link m-menu__toggle">
<i class="m-menu__link-icon flaticon-layers"></i>
<span class="m-menu__link-text">FAQ</span>
<i class="m-menu__ver-arrow la la-angle-right"></i>
</a>
<div class="m-menu__submenu " m-hidden-height="840">
<span class="m-menu__arrow"></span>
<ul class="m-menu__subnav">
<li class="m-menu__item m-menu__item--active" aria-haspopup="true">
<a href="{{ url('/') }}/admin/faq/list/1" class="m-menu__link ">
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
<span></span>
</i>
<span class="m-menu__link-text">English</span>
</a>
</li>
<li class="m-menu__item m-menu__item" aria-haspopup="true">
<a href="{{ url('/') }}/admin/faq/list/2" class="m-menu__link ">
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
<span></span>
</i>
<span class="m-menu__link-text">Korean</span>
</a>
</li>
<li class="m-menu__item m-menu__item" aria-haspopup="true">
<a href="{{ url('/') }}/admin/faq/list/3" class="m-menu__link ">
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
<span></span>
</i>
<span class="m-menu__link-text">Chinese</span>
</a>
</li>
</ul>
</div>
</li>
as I understand, you want to change your menu classes by the current url..
laravel has is() method in Request class. You may want to use it.
class="{{Request::is('category/products') ? 'm-menu__item--active' : 'm-menu__item--open'}}"
if your current url base-url/category/products then you're gonna get the 'm-menu__item--active' class

Laravel HREF techniques for multiple pages

<!-- BEGIN HEADER MENU -->
<div class="nav-collapse collapse navbar-collapse navbar-responsive-collapse">
<ul class="nav navbar-nav">
<li class="dropdown dropdown-fw dropdown-fw-disabled active open selected">
<i class="icon-home"></i> Home
<ul class="dropdown-menu dropdown-menu-fw">
<li>
<i class="icon-bar-chart"></i> View Photo
</li>
<li class="active">
<i class="icon-bulb"></i> About
</li>
<li>
<i class="icon-graph"></i> Contact
</li>
</ul>
</li>
<li class="dropdown dropdown-fw dropdown-fw-disabled">
<i class="icon-home"></i> Upload
<ul class="dropdown-menu dropdown-menu-fw">
<li>
<i class="icon-bar-chart"></i> Upload Photo
</li>
<li>
<i class="icon-bulb"></i> View Photo List
</li>
</ul>
</li>
</ul>
</div>
I am still new to this but basically, I have 5 pages (View Photo, About, Contact, Upload Photo, View Photo List). Currently, I want to show this HTML in all 5 pages so that it will be standardized. If I change the "picture/about" in one page to "photograph/about" for example, the 5 pages will need to reflect this change. This gets more complex as the number of pages increases.
Is there any way or technique in Laravel to solve this issue? Thanks.
Create a template file like Laravel provides app.blade.php in resources/template/ directory, use extends, sections etc for designing, please read Laravel Documentation for Templates
You can use partials for this.
If your issue is adding the active class to the correct link then you can just use request()->is() to check the current url:
<li class="{{ request()->is('picture/externalphotoviewer') ? 'active' : '' }}">
<a href="{{ url('picture/externalphotoviewer') }}">
<i class="icon-bar-chart"></i> View Photo </a>
</li>
<li class="{{ request()->is('picture/about') ? 'active' : '' }}">
<a href="{{ url('picture/about') }}">
<i class="icon-bulb"></i> About </a>
</li>
<li class="{{ request()->is('picture/contact') ? 'active' : '' }}">
<a href="{{ url('picture/contact') }}">
<i class="icon-graph"></i> Contact </a>
</li>
Simply create a blade file inside your resources/views directory and then use #include e.g.
reasources/views/partials/header.blade.php:
<div class="nav-collapse collapse navbar-collapse navbar-responsive-collapse">
<ul class="nav navbar-nav">
<li class="dropdown dropdown-fw dropdown-fw-disabled active open selected">
<a href="javascript:;" class="text-uppercase">
<i class="icon-home"></i> Home </a>
<ul class="dropdown-menu dropdown-menu-fw">
<li class="{{ request()->is('picture/externalphotoviewer') ? 'active' : '' }}">
<a href="{{ url('picture/externalphotoviewer') }}">
<i class="icon-bar-chart"></i> View Photo </a>
</li>
<li class="{{ request()->is('picture/about') ? 'active' : '' }}">
<a href="{{ url('picture/about') }}">
<i class="icon-bulb"></i> About </a>
</li>
<li class="{{ request()->is('picture/contact') ? 'active' : '' }}">
<a href="{{ url('picture/contact') }}">
<i class="icon-graph"></i> Contact </a>
</li>
</ul>
</li>
<li class="dropdown dropdown-fw dropdown-fw-disabled">
<a href="javascript:;" class="text-uppercase">
<i class="icon-home"></i> Upload </a>
<ul class="dropdown-menu dropdown-menu-fw">
<li>
<a href="{{ url('photo/create') }}">
<i class="icon-bar-chart"></i> Upload Photo </a>
</li>
<li>
<a href="{{ url('photo') }}">
<i class="icon-bulb"></i> View Photo List </a>
</li>
</ul>
</li>
</ul>
</div>
Then replace the header code in your other blade files with:
#include('partials.header')
NB
If you change the location of the header you will need to update the #include's as well e.g.
e.g. resources/views/layouts/main/header.blade.php would be #include('layouts.main.header')
Hope this helps!

How to pass a variable without Controller in Laravel 5.4?

I have a application with extends a view with name "notification". How you can see in the picture.
That fragment is just a list, don't extends anything, How I pass a variable to that list? Something fixed. Any suggestion?
<li class="dropdown notifications-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="livicon" data-name="bell" data-loop="true" data-color="#e9573f"
data-hovercolor="#e9573f" data-size="28"></i>
<span class="label label-warning">7</span>
</a>
<ul class=" notifications dropdown-menu drop_notify">
<li class="dropdown-title">Você tem novas notificações</li>
<li>
<!-- inner menu: contains the actual data -->
<ul class="menu">
#foreach($notificacao as $value)
<li>
<i class="livicon default" data-n="asterisk" data-s="20" data-c="white"
data-hc="white"></i>
Você tem novas perguntas
<small class="pull-right">
<span class="livicon paddingright_10" data-n="timer" data-s="10"></span>
{{$value->created_at->diffForHumans()}}
</small>
</li>
#endforeach
</ul>
</li>
<li class="footer">
View all
</li>
</ul>
</li>

Resources