Ander Gonzalez Ortiz Ander Gonzalez Ortiz - 7 months ago 9
PHP Question

How to copy a div contenent to a txt file from a large html page

I need to copy the number of percent of the progress bar from this page to a txt file. (http://tienda.insidecraft.com/)

I have tried something like this:



$(document).on("ready", function() {
setInterval(querygoal, 5000);
querygoal();
$(".navbar-brand").tooltip({placement: "bottom", html: true});
$("[data-toggle='tooltip']").tooltip();
});

function querygoal() {
$.ajax({
url: "view-source:http://tienda.insidecraft.com/",
method: "GET",
success: function(res){
if (res["status"]) {
actualizarJugadores2(res["bar"]["style"]);
}
}
});
}

function actualizarJugadores2(num) {
var digitos = ("" + num).split("");
var elem = $(".goal").children("dd");
elem.empty();
for (index = 0; index < digitos.length; index++){
elem.append("<span>" + digitos[index] + "</span>")
}
var color = "#F1A90F";

if (num==0) {
color = "#d9534f"
}
elem.children("span").css("background-color",color);
}





Anyone can help me?

Thanks in advance.

Answer

Your question is tagged as PHP, so I guess that's an alternative? Simply parse the webpage with PHP Simple HTML DOM Parser. In the example beneath I use the style attribute to find the correct paragraph.

Code:

<?php
    include 'simple_html_dom.php';

    $html = file_get_html('http://tienda.insidecraft.com/');

    foreach($html->find('p[style="text-align:center; font-size:14px;"]') as $item) {
        $result = trim($item->plaintext);
    }

    $progress = explode( ' ', $result)[0];
    echo $progress;
?>

Output:

72%