Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Update html table rows with new values at runtime

by marto (Cardinal)
on Apr 24, 2020 at 06:30 UTC ( [id://11116002]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Update html table rows with new values at runtime
in thread Update html table rows with new values at runtime

"I ran rest api to get that html table data in the json format."

You didn't show this, you just provided some messy html. The code below prints out data matching your criteria

#!/usr/bin/perl use strict; use warnings; use Mojo::DOM; use feature 'say'; my $html = <DATA>; my $dom = Mojo::DOM->new( $html ); foreach my $row ( $dom->at('tr > th > a[href^=bus00eqa/')->parent->par +ent ){ foreach my $e ( $row->find('th')->each ){ say $e->all_text; } }; __DATA__ <table class=\"relative-table wrapped\" style=\"width: 100.0%;\"><colg +roup><col style=\"\" /><col style=\"width: 5.3799%;\" /><col style=\" +width: 3.34865%;\" /><col style=\"width: 5.17157%;\" /><col style=\"w +idth: 5.22365%;\" /><col style=\"width: 9.49449%;\" /><col style=\"wi +dth: 20.0674%;\" /><col style=\"\" /><col style=\"width: 5.90074%;\" +/><col style=\"width: 3.45282%;\" /><col style=\"width: 15.1716%;\" / +><col style=\"width: 5.08824%;\" /></colgroup><tbody><tr><td>Envviron +ment</td><td colspan=\"1\">Last Updated</td><td colspan=\"1\">RPD</td +><td colspan=\"1\">Usage</td><td>Status</td><td>ADW</td><td>Schema</t +d><td colspan=\"1\">Wallet</td><td colspan=\"1\">FA Source</td><td>OA +C</td><td>OA4F-GA-BITBUCKET-REPO</td><td>Comments</td></tr><tr><th cl +ass=\"highlight-green\" colspan=\"1\" data-highlight-colour=\"green\" +><a href=\"https://confluence.domaincorp.com/confluence/display/FAW/d +en00pyy\" title=\"\" rel=\"nofollow\">bus00eqa</a></th><th class=\"hi +ghlight-green\" colspan=\"1\" data-highlight-colour=\"green\">25-Apr- +2020</th><th class=\"highlight-green\" colspan=\"1\" data-highlight-c +olour=\"green\">5.6</th><th class=\"highlight-green\" colspan=\"1\" d +ata-highlight-colour=\"green\"><pre title=\"\"><span style=\"color: r +gb(29,28,29);\"><span style=\"color: rgb(23,43,77);text-decoration: n +one;\" title=\"\"><span style=\"color: rgb(23,43,77);text-decoration: + none;\" title=\"\"><span style=\"color: rgb(29,28,29);\">CRM<br /></ +span></span></span></span></pre></th><th class=\"highlight-green\" co +lspan=\"1\" data-highlight-colour=\"green\">Available</th><th class=\ +"highlight-green\" colspan=\"1\" data-highlight-colour=\"green\"><spa +n title=\"\">oax487389368_low</span><br title=\"\" /><strong title=\" +\"> </strong></th><th class=\"highlight-green\" colspan=\"1\" data-hi +ghlight-colour=\"green\"><span style=\"color: rgb(23,43,77);text-deco +ration: none;\" title=\"\"><span style=\"color: rgb(23,43,77);text-de +coration: none;\" title=\"\"><span style=\"color: rgb(29,28,29);\"><s +pan style=\"color: rgb(0,51,102);\" title=\"\"><span style=\"color: r +gb(29,28,29);\"><span style=\"color: rgb(23,43,77);text-decoration: n +one;\" title=\"\"><span style=\"color: rgb(29,28,29);\"><span><span s +tyle=\"color: rgb(23,43,77);text-decoration: none;\" title=\"\"><span + style=\"color: rgb(29,28,29);\"><span>OAX$OAC/U20O2LRDjg9MN9QSySJov9 +2LF7CrZ3<br /><br /></span></span></span></span></span></span></span> +</span><br /></span></span></span></th><th class=\"highlight-green\" +colspan=\"1\" data-highlight-colour=\"green\"><a class=\"external-lin +k\" href=\"http://slc08ulx.us.domain.com:8000/integ1/test3dp3jan31ext +ernalWallet.zip\" title=\"\" rel=\"nofollow\">http://slc08ulx.us.doma +in.com:8000/integ1/test3dp3jan31externalWallet.zip</a></th><th class= +\"highlight-green\" colspan=\"1\" data-highlight-colour=\"green\">FA5 +.0-20.01</th><th class=\"highlight-green\" colspan=\"1\" data-highlig +ht-colour=\"green\">5.0</th><th class=\"highlight-green\" colspan=\"1 +\" data-highlight-colour=\"green\"><a title=\"\" rel=\"nofollow\" cla +ss=\"external-link\" href=\"http://bus00cyb.us.domain.com:8080/job/OA +4F-3.1-BITBUCKET-REPO/25/\">http://bus00cyb.us.domain.com:8080/job/OA +4F-3.1-BITBUCKET-REPO/25/</a></th><th class=\"highlight-green\" colsp +an=\"1\" data-highlight-colour=\"green\">NONE</th></tr><tr><th class= +\"highlight-green\" data-highlight-colour=\"green\"><a rel=\"nofollow +\" href=\"https://confluence.domaincorp.com/confluence/display/FAW/bu +s00eqz\" title=\"\">bus00eqz</a></th><th class=\"highlight-green\" co +lspan=\"1\" data-highlight-colour=\"green\">29-Feb-2020</th><th class +=\"highlight-green\" colspan=\"1\" data-highlight-colour=\"green\">3. +1</th><th class=\"highlight-green\" colspan=\"1\" data-highlight-colo +ur=\"green\"><p title=\"\">HCM</p></th><th class=\"highlight-green\" +data-highlight-colour=\"green\">Available</th><th class=\"highlight-g +reen\" data-highlight-colour=\"green\"><span title=\"\">dbdoublecore< +/span></th><th class=\"highlight-green\" data-highlight-colour=\"gree +n\"><span style=\"color: rgb(23,43,77);text-decoration: none;\" title +=\"\"><span style=\"color: rgb(29,28,29);\"><span><span style=\"color +: rgb(23,43,77);text-decoration: none;\" title=\"\"><span style=\"col +or: rgb(29,28,29);\"><span>C5.632920_OAX$DW/Welcome12345<br /></span> +</span></span></span></span></span></th><th class=\"highlight-green\" + colspan=\"1\" data-highlight-colour=\"green\"><a title=\"\" class=\" +external-link\" href=\"http://slc08ulx.us.domain.com:8000/wallets/faw +dev/Wallet_oax487389368_low1.zip\" rel=\"nofollow\">http://slc08ulx.u +s.domain.com:8000/wallets/fawdev/Wallet_oax487389368_low1.zip</a></th +><th class=\"highlight-green\" colspan=\"1\" data-highlight-colour=\" +green\">FA5.0-20.01</th><th class=\"highlight-green\" data-highlight- +colour=\"green\">5.0</th><th class=\"highlight-green\" data-highlight +-colour=\"green\"><a class=\"external-link\" rel=\"nofollow\" href=\" +http://bus00cyb.us.domain.com:8080/job/OA4F-3.1-BITBUCKET-REPO/10/\"> +http://bus00cyb.us.domain.com:8080/job/OA4F-3.1-BITBUCKET-REPO/10/</a +></th><th class=\"highlight-green\" data-highlight-colour=\"green\">N +ONE</th></tr><tr><td class=\"highlight-green\" title=\"Background col +our : Green\" colspan=\"1\" data-highlight-colour=\"green\"><p title= +\"\"><strong><a rel=\"nofollow\" href=\"https://confluence.domaincorp +.com/confluence/display/FAW/bus00eqz\" title=\"\">den00pyy</a></stron +g></p><p title=\"\"><br /></p></td><td class=\"highlight-green\" titl +e=\"Background colour : Green\" colspan=\"1\" data-highlight-colour=\ +"green\"><strong>25-Apr-2020</strong></td><td class=\"highlight-green +\" title=\"Background colour : Green\" colspan=\"1\" data-highlight-c +olour=\"green\"><strong>5.6</strong></td><td class=\"highlight-green\ +" title=\"Background colour : Green\" colspan=\"1\" data-highlight-co +lour=\"green\"><strong>FPHDEV</strong></td><td class=\"highlight-gree +n\" title=\"Background colour : Green\" colspan=\"1\" data-highlight- +colour=\"green\"><strong>Available</strong></td><td class=\"highlight +-green\" title=\"Background colour : Green\" colspan=\"1\" data-highl +ight-colour=\"green\"><strong>oax487389368_low1</strong></td><td clas +s=\"highlight-green\" title=\"Background colour : Green\" colspan=\"1 +\" data-highlight-colour=\"green\"><strong>test$username/Welcome12345 +</strong></td><td class=\"highlight-green\" title=\"Background colour + : Green\" colspan=\"1\" data-highlight-colour=\"green\"><strong>http +://slc08ulx.us.domain.com:8000/integ1/test3dp3jan31externalWallet.zip +</strong></td><td class=\"highlight-green\" title=\"Background colour + : Green\" colspan=\"1\" data-highlight-colour=\"green\"><p title=\"\ +"><strong>FA5.6-20.01</strong></p></td><td class=\"highlight-green\" +title=\"Background colour : Green\" colspan=\"1\" data-highlight-colo +ur=\"green\"><strong>5.0</strong></td><td class=\"highlight-green\" t +itle=\"Background colour : Green\" colspan=\"1\" data-highlight-colou +r=\"green\"><strong><a rel=\"nofollow\" href=\"http://bus00cyb.us.dom +ain.com:8080/job/OA4F-3.1-BITBUCKET-REPO/10/\" title=\"\">http://bus0 +0cyb.us.domain.com:8080/job/OA4F-3.1-BITBUCKET-REPO/25/</a></strong>< +/td><td class=\"highlight-green\" title=\"Background colour : Green\" + colspan=\"1\" data-highlight-colour=\"green\"><strong>NONE</strong>< +/td></tr></tbody></table>

As far as manipulating the DOM goes see Re: Batch remove URLs or Super Search for more examples. If your data is coming from an online source just use Mojo::UserAgent to get it directly.

Update: A further explanation, using Mojo::UserAgent you can grab your data, and access the resulting DOM (illustrated above by reading in the HTML you provided, stored within __DATA__) like so:

use Mojo::UserAgent; my $ua = Mojo::UserAgent->new; my $url = 'https://target/url/or/endpoint'; my $dom = $ua->get( $url )->res->dom; # if the result is HTML my $dom = $ua->get( $url )->res->json; #if the result is JSON

The documentation shows examples of authentication. With the method above you can select the row you wish to edit, rather than being hard coded this selector could be something you prompt for. Some small additional steps are required if you want to change both the href attribute and the link text, but it's not a big deal. say $dom->content will dump the updated DOM, you can simply save this to file or send it on to another endpoint, whatever your end goal is. Like I said, Super Search will find lots of examples. Some more to get you started:

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116002]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2024-04-19 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found