Im working wiht some home automation tools which displays energy usage using some widgets created but others smarter than I.
I can get this to work, it will display usage in KW however its incorrect.
The same of the watts should be portion of a KW
Can anyone point me in the direction of resolving this so it shows 0.XX please
<div class="widget">
<div class="icon off">
<svg viewBox="0 0 48 48">
<use xlink:href="/static/matrix-theme/squidink.svg#thunder-1">
</use>
</svg>
</div>
<div class="name">Power</div>
<div class="valueGroup">
<div class="value">
{{itemValue('LivingRoomNum2')*1 + itemValue('KitchenNum2') | number:2}} kW
</div>
<div class="value">
{{itemValue('LivingRoomNum1')}} W (Living)
</div>
<div class="value">
{{itemValue('KitchenNum1')}} W (Kitchen)
</div>
</div>
</div>
I suspect that from function itemValue() returned value is of type string and this is causing wrong calculation. Make sure you parse the result as number. You can use parseFloat() when returning from itemValue().
Check the sample:
var app = angular.module('test', []);
app.controller('AppController', ['$scope', function($scope) {
}]);
app.run();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="test" ng-controller="AppController" class="widget">
<div class="value">Wrong: {{'12.5' * 1 + '10' | number:2}} kW</div>
<div class="value">Correct: {{12.5 * 1 + 10 | number:2}} kW</div>
</div>
Add the | number:2 filter within the {{ }} of the 2nd and 3rd values. This filter allows numbers to be shown in decimals. Also make sure the data isn't string.
<div class="widget">
<div class="icon off">
<svg viewBox="0 0 48 48">
<use xlink:href="/static/matrix-theme/squidink.svg#thunder-1">
</use>
</svg>
</div>
<div class="name">Power</div>
<div class="valueGroup">
<div class="value">
{{(itemValue('LivingRoomNum2')*1 + itemValue('KitchenNum2')*1)/1000}} kW
</div>
<div class="value">{{itemValue('LivingRoomNum1')}} W (P1)</div>
<div class="value">{{itemValue('KitchenNum1')}} W (P2)</div>
</div>
</div>
This fixed it. My actual number is indeed a string
Related
I'm trying to recursively insert a div element that contains a button as follows:
<div v-for="column in 25" :key="column.id" class="columna">
<div v-for="row in 10" :key="row.id" class="recuadro">
{{ row == 1 ? 'PAXXX' : `<div class="selector"><button onclick="colorCell()" /></div>` }}
</div>
</div>
Basically it inserts row element name first and then fulfills the row with a selectable div that has an invisible button.
I'm getting syntax error in <div class="selector"><button onclick="colorCell()" /></div>:
Missing ` (placed right under <div...)
Any suggest will be appreciated
This code from the question above:
{{ row == 1
? 'PAXXX'
: `<div class="selector"><button onclick="colorCell()" /></div>`
}}
Is not valid, as you can place only text (not HTML) inside double mustaches.
Using v-if and v-else works as intended and avoids the syntax error:
<div v-for="column in 25" :key="column.id" class="columna">
<div v-for="row in 10" :key="row.id" class="recuadro">
<span v-if="row == 1">PAXXX</span>
<div v-else class="selector"><button onclick="colorCell()" /></div>
</div>
</div>
Or you can use the v-html attribute to tell vue to treat the contents as raw HTML.
<div v-for="column in 25" :key="column.id" class="columna">
<div v-for="row in 10" :key="row.id" class="recuadro"
v-html="row == 1 ? 'PAXXX' : `<div class='selector'><button onclick='colorCell()' /></div>`"
>
</div>
I have a website from which I want to extract values using XPATH. These values are changable but generally they are in same repeated node trees (there are hundreds of same structurally node trees with this one changeable value). This is example of one of these tree:
<div style="position: absolute; left: 0px; top: 178px; height: 89px; width: 100%;">
<a class="css-18rtd1e" href="/offers/appunite-backend-developer-elixir">
<div class="css-ysfq6d"></div>
<div class="css-1anw03b"><img src="https://bucket.justjoin.it/offers/company_logos/thumb/22f3ad736e1bc02190ff8beb9d4c55a4de297104.png?1572275788" alt="AppUnite" class="css-h8h6qh"></div>
<div class="css-rmb95w">
<div class="css-fxb39h">
<div class="css-18hez3m">
<div class="css-1x9zltl">Elixir Developer</div>
<div class="css-1suuexb"><span class="css-5fhp0m">Online<br>interview</span></div>
</div>
<div class="css-16tql6o">
<span class="css-112rr0w">7 000 - 11 000 PLN </span>
<div class="css-hw5uoy">New</div>
</div>
</div>
<div class="css-m6o8yl">
<div class="css-pdwro7">
<div class="css-ajz12e">
<svg class="MuiSvgIcon-root" focusable="false" viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 7V3H2v18h20V7H12zM6 19H4v-2h2v2zm0-4H4v-2h2v2zm0-4H4V9h2v2zm0-4H4V5h2v2zm4 12H8v-2h2v2zm0-4H8v-2h2v2zm0-4H8V9h2v2zm0-4H8V5h2v2zm10 12h-8v-2h2v-2h-2v-2h2v-2h-2V9h8v10zm-2-8h-2v2h2v-2zm0 4h-2v2h2v-2z"></path>
</svg>
AppUnite
</div>
<div class="css-1ihx907">
<svg class="MuiSvgIcon-root" focusable="false" viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 2C8.13 2 5 5.13 5 9c0 4.17 4.42 9.92 6.24 12.11.4.48 1.13.48 1.53 0C14.58 18.92 19 13.17 19 9c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"></path>
</svg>
Poznań
</div>
<span class="css-5fhp0m">Online interview</span>
</div>
<div class="css-1ij7669">
<div class="tag css-1g8us6r">Phoenix</div>
<div class="tag css-1g8us6r">Elixir</div>
<div class="tag css-1g8us6r">Web Applications</div>
</div>
</div>
</div>
</a>
</div>
I want to extract word AppUnite and it would be simple task but there is one condition to be met: I need to use in my XPATH element containing text from "css-1x9zltl" class (in this case it would be word Elixir Developer). In other words I want to get access to AppUnite using extracted word from "css-1x9zltl" class. So beginning is simple: //div[contains(#class, "css-1x9zltl") and text()="Elixir Developer"] but what next?
You want to get the names of the hiring companies.
Since the names of the #class attributes are fixed (css-1x9zltl,css-ajz12e) on JJI website, you can use :
//div[contains(#class,"css-1x9zltl")][contains(.,"Elixir Developer")]/following::div[#class="css-ajz12e"][1]/text()
Note this will select "Elixir Developer", "Senior Elixir Developer" offers. To be more strict, remove the second contains :
//div[contains(#class,"css-1x9zltl")][.="Elixir Developer"]/following::div[#class="css-ajz12e"][1]/text()
If I understand you correctly, in the case of the sample in your question, an xpath expression like this may do the trick:
//div[contains(#class, "css-1x9zltl")]["Elixir Developer"]/ancestor::div[#class="css-fxb39h"][1]/following-sibling::div [#class="css-m6o8yl"]//div[#class="css-ajz12e"]/text()
This expression basically locates the <div> node meeting your class and text conditions, goes up to the first ancestor which is a sibling of the <div> node in which the target text is buried, then goes down to the <div>child node (of that sibling) which contains the target text, and finally selects the text node of that child node.
I am trying to make web crawler, using scrapy from python, that extracts the information that google shows in the right side when you make a search, for example:
I want to extract the information in the box in the rigth side
The link is: search in google
The source code: source code
Part of the HTML code is:
<div class="g rhsvw kno-kp mnr-c g-blk" lang="es-419" data-hveid="CAoQAA" data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQjh8oAHoECAoQAA">
<div class="kp-blk knowledge-panel Wnoohf OJXvsb" data-hveid="CAoQAQ" data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQww0oAHoECAoQAQ">
<div class="xpdopen">
<div class="ifM9O">
<div>
<div></div>
</div>
<div data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQ_xd6BAgKEAI">
<div class="kp-header" lang="es-419" data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQ3z56BAgEEAA">
<div lang="es-419">
<h2 class="bNg8Rb">Resultado del Gráfico de conocimiento
</h2>
</div>
<div class="kp-hc">
<div class="NFQFxe Hhmu2e viOShc LKPcQc mod" data-md="16" lang="es-419" style="clear:none" data-hveid="CAQQAQ" data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQhygoADAbegQIBBAB">
<!--m-->
<div class="Ftghae iirjIb">
<div class="rsir2d">
<kno-share-button>
<div jsaction="r._HouY4r6utk" data-rtid="iHUQypqXTr0Q" jsl="$t t-dhmk9MkDbvI;$x 0;" class="r-iHUQypqXTr0Q" data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQ-YABKAAwG3oECAQQAg"><span class="JP8rKe r8U5xb z1asCe Fp7My" aria-label="Compartir" role="button" tabindex="0"><svg focusable="false" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24"><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81 1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9c-1.66 0-3 1.34-3 3s1.34 3 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.16c-.05.21-.08.43-.08.65 0 1.61 1.31 2.92 2.92 2.92 1.61 0 2.92-1.31 2.92-2.92s-1.31-2.92-2.92-2.92z"></path></svg></span>
<div style="display:none" class="iHUQypqXTr0Q-YbcQq9Khf_8 r-im11Tgib5Xfc" jsaction="dg_dismissed:r.-FPnppROon0;kno_shr_close_button_clicked:r.giXQqEBMb3E" data-rtid="im11Tgib5Xfc" jsl="$t t-7hzFN84w9_k;$x 0;" data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQ2poBMBt6BAgEEAM">
<g-dialog class="im11Tgib5Xfc-0078sLar460 r-iuKAMqdareQ0" data-id="_RWTdXKfnLs_EswXNnaCQDw4" jsaction="dg_reg_content:r.J_j78ao4uyM" data-rtid="iuKAMqdareQ0" jsl="$t t-cuCqGEujB5w;$x 0;">
<div class="iuKAMqdareQ0-oPwtUFSp9U8" id="_RWTdXKfnLs_EswXNnaCQDw4" jsaction="dg_close:r.99yxp2ZuQP0;r.nUlQmbHCUts" data-rtid="iuKAMqdareQ0" jsl="$x 4;"></div>
</g-dialog>
</div>
<div style="display:none" class="iHUQypqXTr0Q--9_AnHJXi80" data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQhc0CMBt6BAgEEAk"></div>
</div>
</kno-share-button>
</div>
<div class="SPZz6b">
<div class="kno-ecr-pt kno-fb-ctx gsmt" data-local-attribute="d3bn" data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQ3B0oATAbegQIBBAK"><span>La Cuarta</span></div>
<div class="wwUB2c kno-fb-ctx"><span data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQ2kooAjAbegQIBBAL">Periódico</span></div>
</div>
</div>
<!--n-->
</div><i class="GdltXd r-i5fJ88MOldfA" style="display:none" jsl="$t t-izLg50Mkmp4;$x 0;"></i></div>
</div>
<div class="SALvLe farUxc mJ2Mod">
<div class="i4J0ge">
<div class="mod" data-md="50" lang="es-419" style="clear:none" data-hveid="CAUQAA" data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQkCkwHHoECAUQAA">
<!--m-->
<div class="PZPZlf hb8SAc kno-fb-ctx" data-attrid="description" data-hveid="CAUQAQ" data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQziAoADAcegQIBRAB">
<div jsl="$t t-oF0h478wPRI;$x 0;" class="r-igZyUtaLvb3g">
<div class="kno-rdesc r-iNUajC5fIXTY" jsaction="sngtp:r.Eddvt4h-GI8;tp_btn:r.Eddvt4h-GI8" data-rtid="iNUajC5fIXTY" jsl="$t t-JgTEvN6zUII;$x 0;">
<div>
<h3 class="bNg8Rb">Descripción</h3><span>La Cuarta es un periódico chileno de circulación nacional diaria, editado por el consorcio Copesa. Su primer número fue publicado el 13 de noviembre de 1984. Su eslogan hasta 2017 fue El diario popular.</span><span><span> </span><a class="q ruhjFe NJLBac fl" href="https://es.wikipedia.org/wiki/La_Cuarta" data-ved="2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQmhMwHHoECAUQAg" ping="/url?sa=t&source=web&rct=j&url=https://es.wikipedia.org/wiki/La_Cuarta&ved=2ahUKEwjnnabakqDiAhVP4qwKHc0OCPIQmhMwHHoECAUQAg">Wikipedia</a></span>
</div>
</div>
</div>
</div>
I saw that the information i want is nested in a lot of div tags and finally is the description of a span tag, so I tried the following:
response.xpath("//div[#class='kno-rdesc']")
response.xpath("//div[#class='mod']")
response.xpath("//div[#class='i4J0ge']")
I just get emprty, I even tried like following each of the tags like this:
response.xpath("//div//div//div//div//div//div//div//div//div//span")
But still can't get to the info I want
xpath is not always a good approach to get data. Many times xpaths is changed accordingly to changed in DOM and even changed in every load.
And use these modules with scrapy when crawl famous websites.
scrapy-rotating-proxies
scrapy-user-agents
otherwiese google detect you request as robot request and block the page load.
The better way to find something on page by classes and id
(Note - you have to notice that class and id not changed on every load and on every query changed).
I am trying to generate a table using angular code in HTML. Now I seem to have how I want the table to look which is how I have set up this code:
<div class="row">
<div class="col col-25">Date</div>
<div class="col col-50">Name of Customer</div>
<div class="col col-25">Hours Used</div>
</div>
What I have done is generated a list in angular code (which is done correctly) and I have ordered them in a certain way with Date being the first entry and Hours Used being the last. To generate the table in HTML, I use this code:
<div class="row">
<div ng-repeat="B in ConvertToTableRow(T) track by $index">
<div class="col col-25" ng-if="$index == 0">
{{ B }}  
</div>
<div class="col col-50" ng-if="$index == 1">
{{ B }}  
</div>
<div class="col col-25" ng-if="$index == 2">
{{ B }}  
</div>
</div>
</div>
Everything in the first row works well and styled to what I need it to be but the second entry (when the index is 1) will never style its table to a col-50 but instead will stick with a col-25. Now I have tested to see the if the values are equal to 1 or 2 but it seems that is working correctly and the infomation is also coming out correctly but its just not styling correctly.
Is it possible to style a table this way using Angular and HTML?
Would it not be better to use ng-class? I think there's an even better way, but this is just off the top of my head. I hope this helps! :) Documentation for ng-class
<div class="row">
<div ng-repeat="B in ConvertToTableRow(T) track by $index">
<div class="col" ng-class="{'col-25': $index % 3 !== 1, 'col-50': $index % 3 === 1}">
{{ B }}  
</div>
</div>
</div>
My target is to search my notes by Title and truncate Body by a letters or words limit. I don't know if its possible to do that and how. I don't want to mess up with any custom filters , directives etc.
This is a idea of the html:
<section class="notespage" ng-controller="NotesController">
<h2>Notes list</h2>
<div>
Search:
<input type="text" ng-model="searchText">
</div>
<div class="notesleft">
<div class="notelist">
<div ng-repeat="note in notes | filter:searchText | truncate:{body:letterLimit}">
<div><h3>{{note.title}}</h3></div>
<div>{{note.body}}</div>
</div>
</div>
</div>
</section>
Where this should be ? In NotesController ?
$scope.letterLimit = 20 ;
Since you don't want to "mess up" with custom filters etc, you can use the built-in limitTo filter to limit the number of characters displayed as note.body:
$scope.letterLimit = 20;
<div>Search:<input type="search" ng-model="searchText" /></div>
<div ng-repeat="note in notes | filter:searchText">
<div><h3>{{note.title}}</h3></div>
<div>{{note.body | limitTo:letterLimit}}</div>
<div>
See, also, this short demo.