Unable to scrape information from website using IMPORTHTML - web-scraping

I'm attempting to copy the information from a website directly into my Google Sheets for some analysis. Below is the HTML element from the said website.
<div><span id="diodia" style="display: inline-block;">Διόδια<span style="color:red;">*</span>: <strong>19.35€</strong> </span><span id="showHideTolls" style="display: inline-block;"><span id="tollsVehicle"><select id="selectSth" style="background: url(https://vriskoapostasi.gr/images/car.png) left no-repeat;width:45px;-webkit-appearance: menulist"><option value="0" selected="selected"></option><option value="1">Αυτοκίνητο</option><option value="2">Δίκυκλο</option>
<option value="3">Αυτοκινούμενο υψ>2.7μ μηκ>5μ</option><option value="4">Λεωφορείο θέσεις>39</option>
<option value="5">Φορτηγό 2 άξονες</option><option value="6">Φορτηγό 3 άξονες</option>
<option value="7">Φορτηγό αξ>=4</option>
</select></span><span id="messageTolls"></span><span> <input type="checkbox" id="isTollSelected"></span></span></div>
What I want to get is the 19.35€ price located in the div above.
I use IMPORTHTML as follows:
=IFERROR(IMPORTHTML(A1, "//*[#id='diodia']/strong"), 0) # Where A1 holds the website link
But every time I get 0 because the content is empty. Why is that happening? Is there any workaround that I'm missing?
Thanks you in advance.

Related

CSS - Hide every element of the same kind except the first - not child

I've been trying to figure out the way to hide every 'label' element in the html below except the first one. I've got a repeater field that adds a row with a dropdown select field and a label.
Each new row adds the select field and the label. The label id starts with 'label-repeat- ' and the suffix is dynamically generated based on the number of repeater rows, so it goes: 'label-repeat-1', 'label-repeat-2', 'label-repeat-3' etc.
The issue is that each repeater row is separately wrapped into its own div, so I'm guessing I cannot use :not(:first-child) in the case.
Here is my fiddle and below is my html:
<div class="fieldset">
<div class="status">
<label id="label-repeat-1" class="label-repeater">Status</label>
<select id="field-repeat-1" class="field-repeater">
<option value="Open">Open</option>
<option value="Closed">Closed</option>
</select>
</div>
</div>
<div class="fieldset">
<div class="status">
<label id="label-repeat-2" class="label-repeater">Status</label>
<select id="field-repeat-2" class="field-repeater">
<option value="Open">Open</option>
<option value="Closed">Closed</option>
</select>
</div>
</div>
<div class="fieldset">
<div class="status">
<label id="label-repeat-3" class="label-repeater">Status</label>
<select id="field-repeat-3" class="field-repeater">
<option value="Open">Open</option>
<option value="Closed">Closed</option>
</select>
</div>
</div>
I've been trying to use the wildcard selector to select the label with label[id^='label-repeat-'], label[id*=' label-repeat-'] which works fine, but then I'm trying to add the :nth-of-type(n+2) pseudo class to select every label except the first one and hide it, but that doesn't seem to work.
label[id^='label-repeat-']:nth-of-type(n+2),
label[id*=' label-repeat-']:nth-of-type(n+2) {
display: none !important;
}
Is there any other way to do this with CSS? Or even jQuery?
If I understand, you want to hide all except for the first label. So, you would end up with a label and 3 select boxes under it? Using the "plus" combinator in CSS is the easiest way of saying "all but the first one"...
.fieldset + .fieldset label {
display:none;
}
This rule is saying any fieldset that is followed by another fieldset (all but the first one), then the nested label under those.

Silverstripe 4 - How do you enable FullTextSearchable and $SearchForm?

Upgrading site from 3 to 4. Existing code makes use of FullTextSearchable as per this guide that exists for 3, but not for 4. Google only results in unanswered questions of the same nature. Except for this one, which doesn't help. But I do find this guide for SS4, which is not geared towards the same topic really, but somewhat helpful.
Here is my code:
_config.php
\SilverStripe\ORM\Search\FulltextSearchable::enable();
Page.php
use SilverStripe\ORM\Connect\MySQLSchemaManager;
private static $create_table_options = [
MySQLSchemaManager::ID => 'ENGINE=MyISAM'
];
Page.ss
$SearchForm
Expected: Standard search form is displayed
Actual: Nothing is displayed
I went as far as to hard code the form from the existing site onto the template to see if the search function itself works:
Page.ss
<form id="SearchForm_SearchForm" action="/home/SearchForm" method="get" enctype="application/x-www-form-urlencoded">
<p id="SearchForm_SearchForm_error" class="message " style="display: none"></p>
<fieldset>
<input type="text" name="Search" value="Search" class="text nolabel" id="SearchForm_SearchForm_Search">
<div class="form-group">
<input type="submit" name="action_results" value="Go" class="action" id="SearchForm_SearchForm_action_results">
</div>
</fieldset>
</form>
Expected: Search results page displays with relevant search results for the entered term
Actual: 404 page not found

Hidden field value with spaces in jsp [duplicate]

I have a strange issue with dropdown boxes in jsp/servlet. Here it is...
<select name="locdropdown" onchange="javascript:change()" >
<%
for(LocationDO locationDO : locationList){%>
<option value=<%=locationDO.getLocationName().trim()%>><%=locationDO.getLocationName().trim()%></option>
<%} %>
</select>
values displayed are:
BI Sholingar
BI Mahindra City
BI Sanand
Rolltec_DTA
Aztec Auto Ltd
BI Gurgoan
and here is how I try to read it in servlet.
String locclasses = req.getParameter("locdropdown");
System.out.println(locclasses);
assume I select Aztec Auto Ltd then expected output from servlet is same right. But output is Aztec. similarly, if I select BI Sanand, the actual output that comes is BI
Can someone help please
You need to quote the value.
<option value="<%=locationDO.getLocationName().trim()%>">
The space is namely a HTML attribute separator. A browser with a bit decent syntax highlighter would already have hinted it when you have checked the generated HTML by rightclick page > View Source.
<option value=Aztec Auto Ltd>
versus
<option value="Aztec Auto Ltd">
As said by BalusC in his answer the problem is with your value assignment.
Modify your code as :
<select name="locdropdown" onchange="javascript:change()" >
<%
for(LocationDO locationDO : locationList)
{%>
<option value="<%=locationDO.getLocationName().trim()%>" >
<%=locationDO.getLocationName().trim()%>
</option>
<%}
%>
</select>
Hope this helps.

Wordpress post form goes to 404 page

I'm coding a plugin that requires forms but I'm having some troubles on post sends.
I had read that the fields names can be a problem for this... But I have 3 fields: cmbParkings, cmbTarifas and dpkFechaEntrada.
My plugin register one custom post type called parking-parkia and one taxonomy for this post type with Ciudades as name.
I don't see where the problem can be! Maybe the field values could be a problem?
Explaination of fields:
cmbParkings is a select filled with all my custom posts (value=id, text=title).
cmbTarifas is dependant from cmbParkings, it loads a metadata from the parking-parkia previously selected (by the moment, value and text = metadata value, containing any characters)
dpkFechaEntrada is a date input.
If I do print_r($_POST) on my 404 page, I see my 404 loaded with the correct values from my form in the $_POST variable.
EDIT: I had comment all fields in form and 404 page still appearing on submit.
Form without fields:
<form id="frmFormularioBusqueda" method="post" action="http://mutuaparkia.extrasoft.es/?p=2632">
<div div="divBotonReserva">
<button type="submit" id="btnEnvioParking">Reservar</button>
</div>
</form>
Form with fields:
<form id="frmFormularioBusqueda" method="post" action="http://mutuaparkia.extrasoft.es/?p=2632">
<div id="selectorParking">
<select id="cmbParkings" name="msolla-cmbParkings">
<option value="0">Elige Parking</option>
<option value="2632">Parking Goya</option>
<option value="2633">Parking Córdoba</option>
<option value="2631">Parking Montalbán</option>
</select>
</div>
<div id="divSelectorTarifa">
<select id="cmbTarifas" name="msolla-cmbTarifas">
<option value="0">Elige Tarifa</option>
</select>
</div>
<div id="divSelectorFecha">
<input id="dpkFechaEntrada" name="msolla-dpkFechaEntrada" type="date">
</div>
<div div="divBotonReserva">
<button type="submit" id="btnEnvioParking">Reservar</button>
</div>
Note: the action url exists and it is ok.
Js that change the action form when the first select is changed:
$( document ).ready(function() {
$("#cmbParkings").change(function(){
//http://mutuaparkia.extrasoft.es/?p=2632
if($.isNumeric($("#cmbParkings").val())){
//$("#frmFormularioBusqueda").attr('action', '/?p=' + $("#cmbParkings").val());
$("#frmFormularioBusqueda").attr('action', $("#txtPermalink" + $("#cmbParkings").val()).val());
}
else{
$("#frmFormularioBusqueda").removeAttr( "action" )
}
$("#cmbTarifas").html($("#cmbTarifas" + $("#cmbParkings").val() ).html());
});
});
Edit: inside if, there is a commented line that it was bad. The new line is working fine now.
Thanks to vard, he had seen that changing the action from from url/?p=id
to the custom post permalink, the code works.

how can I open an image in lightbox from a list of dropdown options after clicking the submit button

I have been searching the web for a result all day to solve my question...
I want a list of options, that would each link to a different image. However, instead of the image opening in a new window, I want the image to open in a lightbox on the same page (lightbox evolution for wordpress is the plugin I am using).
I have tried using onclick in input field, and the lightbox will open (if class="lightbox") but no image loads.
I don't know if I need to add a function that will allow the input to recognize which option is selected so that when the input button is clicked, that that specific image opens in a lightbox.
And if I do need a function, I don't know where to add the function... onclick? Somewhere in the option tag, or select tag?
<form>
<select>
<option value="linkimage1.jpg">image 1</option>
<option value="linkimage2.jpg">image 2</option>
<option value="linkimage3.jpg">image 3</option>
<input type="button" value="submit" />
</select>
</form>
Any help would be appreciated, even if it's to a good link that could explain how I could create a function and add it to my code, and then use a solution to call the function into my dropdown.
Thanks
If using iLightBox http://ilightbox.net/ you can do that like this:
<select id="selectImage">
<option>Select Image</option>
<option value="linkimage1.jpg">image 1</option>
<option value="linkimage2.jpg">image 2</option>
<option value="linkimage3.jpg">image 3</option>
</select>
<script>
jQuery(document).ready(function($){
$('select#selectImage').change(function(){
var $this = $(this),
url = $this.val();
$.iLightBox(url);
});
});
</script>

Resources