lundi 28 janvier 2019

Extract specific html values with php

I'm coding a web service which is taking data from various servers.

Currently I'm stuck on a service which does not provide a XML or json response. Just plain HTML.

After having correctly configured all curl requests, this is what I get (will place XXXXXXXXX on private information):

<!DOCTYPE html>
<html>
    <head>
       [...]
    </head>
    <body>
        [...]
        <div id="container">

            <div id="top">
                [...]
</div>
<div class="double-split"></div>            </div>
            <div class="header">
                <div class="header_top">
    <div class="prop_logo">
        <a href="http://www.codiceinverso.it/">
            <img class="banner_head" border="0" alt="CodiceInverso.it" src="http://www.codiceinverso.it/img/title.png">
        </a>        
    </div>

    <div class="prop_1">
        <form action="http://www.codiceinverso.it/search.php" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-5079264506056694:4krgt-spv0m" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="ISO-8859-1" />
    <input type="text" name="q" size="40" />
    <input type="submit" name="sa" value="Cerca" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.it/cse/brand?form=cse-search-box&amp;lang=it"></script>    </div>

    <!-- <div class="social">
        <span class="google">
            <g:plusone size="medium" href="http://www.codiceinverso.it/servizi/verifica-partita-iva.html"></g:plusone>
        </span>
        <span class="facebook">
            <iframe src="https://www.facebook.com/plugins/like.php?href=http://www.codiceinverso.it/servizi/verifica-partita-iva.html&amp;show_faces=false&amp;layout=button_count" scrolling="no" frameborder="0" style="height: 21px; width: 150px" allowTransparency="true"></iframe>
        </span>
    </div> -->
</div>
<div style="text-align: center; margin-top:15px; margin-bottom: 25px;">
        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- cod_inv_header -->
    <ins class="adsbygoogle"
         style="display:inline-block;width:728px;height:90px"
         data-ad-client="ca-pub-5079264506056694" 
         data-ad-slot="4463705778"></ins>
    <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    </div>

<div class="header-menu thisisfixed" rel="191">
    <div class="wrapper">
        <ul class="main-menu">
            
            <li style="background:#a21d1d;color:#a21d1d;">[...]
            </li>
            
            <li style="background:#6d8b13;color:#6d8b13;">[...]
            </li>

            
            
            <li style="background:#338aa6;color:#338aa6;"><a>Codici & Comuni<span> </span></a>
                <ul class="sub-menu">
  [...]
                </ul>
            </li>

            <li style="background:#4b4b4b;color:#4b4b4b;">[...]
            </li>
        </ul>
    </div>
</div>
            </div>
            <div id="main">
                <div id="content">
                                            <div class="wrapper_content">
                            <div class="top_content">
    <a href="http://www.codiceinverso.it/">
        TORNA ALLA HOMEPAGE
    </a>
</div>
<div class="title"><h1>Verifica la Partita IVA</h1></div>                <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDYK1Ql2jSXrghsZEmrTWdhHVqeECcTgLI&language=it"
        type="text/javascript">
</script>
</script>
<script type="text/javascript" src="http://www.codiceinverso.it/ajax/maps.js"></script>
<script type="text/javascript" src="http://www.codiceinverso.it/ajax/service.js"></script>

<div class="page">
              La Partita Iva <strong style="color:green">XXXXXXXXXXX</strong> risulta corretta!!<br>
          Matricola : <strong>XXXXXXXXX</strong> <br>
          Codice di controllo : <strong>XXXXXX </strong><br>
          Rilasciata dalla provincia di <strong>XXXXXXX</strong> <br>
          <br>
          Nome : <strong>XXXXXXXXXXXXXX</strong><br>
          Indirizzo : <strong>XXXXXXXXXXX
XXXXXXXXXXX
</strong><br><br>
          <a href="">Verifica un' altra Partita Iva</a>

                     </div>
<div class="page" style="margin-top: 15px;">
    <br />
    <h2>Che cos'&egrave; la Partita IVA ?</h2>
La <strong>Partita IVA</strong> &egrave; un codice di 11 cifre che viene rilasciato dall'ufficio dell'<strong>Agenzia Entrate</strong>.
Le prime 7 cifre indicano il numero di matricola che identifica il soggetto nell'ambito del distretto provinciale. Le successive 3 cifre
corrispondono invece generalmente al <strong>suffisso Istat</strong> della provincia. L'ultima cifra &egrave; un numero
di controllo che serve per verificare la correttezza della partita IVA. Per maggiori informazioni
    consultare la voce di Wikipedia <a target="_blank" href="http://it.wikipedia.org/wiki/Partita_Iva">Partita Iva</a>
</div>

    
        <div class="adsense_banner_bottom_all_page">
        [...]
    </div>
    
                        </div>
                                    </div>
            </div>
            <div id="extra">
                <div class="content-right">
    
        <div class="banner">
    
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- cod_inv_all_page_336x280 -->
    <ins class="adsbygoogle"
         style="display:inline-block;width:336px;height:280px"
         data-ad-client="ca-pub-5079264506056694" 
         data-ad-slot="1479886577"></ins>
    <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
        </div>
    <div class="separator"></div>
               [...]
    </div>

    <div class="facebook-container">
       [...]
    </div>



</div>


            </div>
            <div id="footer">
                <div class="line_footer"></div>
<div class="footer_text">
[...]
</div>            </div>
        </div>
        <script type="text/javascript">
           [...]
        </script>
    </body>
</html>

I need to get the XXXXXXXXXX values in php separate variables.

What's the easiest way to achieve this? I'm still learning to program web services and I would appreciate if someone can show me the right way to proceed.

Thanks a lot for Your time.

Luca




Aucun commentaire:

Enregistrer un commentaire