How to extract content from a PHP page?

Asked

Viewed 1,453 times

1

Guys I’m basically trying to get some data from SEFAZ, to check if it is online or unavailable at the moment I’m not getting it up because I don’t know, I wonder how I can is picking up a certain line of their code ?

1 answer

4

You can use the get_http_response_code to check if the page is online and then file_get_contents to download the page.

if(get_http_response_code('http://sefaz.com') != "200"){
    echo "erro";
}else{
    $pagina = file_get_contents('http://sefaz.com');
}

To find a certain line after downloading the page, in this case the choice of AP is by the line content MT the library shall be used SIMPLE_HTML_DOM_PARSER

<?php
    include '../../../library/Simple_HTML_DOM/simple_html_dom.php';
    $html = file_get_html( 'http://www.nfe.fazenda.gov.br/portal/disponibilidade.aspx?versao=0.00&tipoConteudo=Skeuqr8PQBY=' );
    $tdMT = NULL;
    foreach($html->find('td') as $td){
        if($td->innertext === 'MT'){
            $tdMT = $td->parent();
            foreach($tdMT->find('td') as $td){
                echo $td->innertext . '<br>';
            }
        }
    }
?>

What is being done:

  1. Inclusion of the library Simple_HTML_DOM
  2. Full page download is made
  3. The search for tags is done td
  4. A check is made if the td is the desired (in case MT)
  5. Attribution is made to the parent element of this td in case the tr
  6. Impression is made of all the elements present within the td daughter of tr (could be done any computation)

*Note: There is besides plain text as MT and - HTML tags inside the td.

Link to download library: Link

  • yes but however I just want to, take a line inside HTML DELE, Saka type I want the <div class="texte"> </div> an example. how do I do ?

  • yes this instead of being the whole site I just want an example line <div class="texte"> <H1> status of Sefaz : .......... </H1></div>

  • http://www.nfe.fazenda.gov.br/portal/availabilityaspx?versao=0.00&tipoConteudo=Skeuqr8PQBY= get on this link I want to pick up the line Where it is written MT whole it

  • how I came to not understand ?

  • @Edwardjunior I edited my reply, the official website this offline momentarily I can upload in the lib Dropbox if you want

  • @Edwardjunior uploaded the lib to Dropbox: https://www.dropbox.com/s/2tzwpcv5zg7y1nr/simple_html_dom.php?dl=0

  • Thank you very much guy worked, but I ask you how I can make an IF NESSE Instead of him bring everything he just gives an ACTIVE OR INACTIVE response , Example If ( the ball is green ) ACTIVE / If No (green ball) Inactive ?

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.