Find values in the page source code

1

You have this website , which generates a table of reserved and available tables, with no need to login:

Oninspection,youcanseethestyleofthediv(ex:class="day closed" ):

Butinthesourcecodeitsaysthis:

<divid="reserve" class="container main">
        <div class="col-md-12 white">
            <h2>Faça sua Reserva</h2>
            <hr class="softly">
            <p class="info-top">Reserve mesa(s) para até <strong>4 pessoas por R$ 12</strong> ou até <strong>6 pessoas por R$ 18</strong> e garanta <strong>50% de desconto nas refeições de toda a mesa</strong>.</p>
            <div id="restaurant-calendar" class="calendar">
                <script id="restaurant-calendar-tpl" type="text/ractive">
                    {{#if loading}}
                        <div class="loader small">
    <div class="loading-spinner"></div>
</div>

<style>
    @-webkit-keyframes rotate-forever {
        0% { -webkit-transform: rotate(0deg); -moz-transform: rotate(0deg); -ms-transform: rotate(0deg); -o-transform: rotate(0deg); transform: rotate(0deg); }
        100% { -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); -ms-transform: rotate(360deg); -o-transform: rotate(360deg); transform: rotate(360deg); }
    }
    @-moz-keyframes rotate-forever {
        0% { -webkit-transform: rotate(0deg); -moz-transform: rotate(0deg); -ms-transform: rotate(0deg); -o-transform: rotate(0deg); transform: rotate(0deg); }
        100% { -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); -ms-transform: rotate(360deg); -o-transform: rotate(360deg); transform: rotate(360deg); }
    }
    @keyframes  rotate-forever {
        0% { -webkit-transform: rotate(0deg); -moz-transform: rotate(0deg); -ms-transform: rotate(0deg); -o-transform: rotate(0deg); transform: rotate(0deg); }
        100% { -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); -ms-transform: rotate(360deg); -o-transform: rotate(360deg); transform: rotate(360deg); }
    }
    .loading-spinner { 
        -webkit-animation-duration: 0.75s;
        -moz-animation-duration: 0.75s;
        animation-duration: 0.75s;
        -webkit-animation-iteration-count: infinite;
        -moz-animation-iteration-count: infinite;
        animation-iteration-count: infinite;
        -webkit-animation-name: rotate-forever;
        -moz-animation-name: rotate-forever;
        animation-name: rotate-forever;
        -webkit-animation-timing-function: linear;
        -moz-animation-timing-function: linear;
        animation-timing-function: linear;
        height: 30px;
        width: 30px;
        border: 4px solid #d5dae2;
        border-right-color: transparent;
        border-radius: 50%;
        display: inline-block;
        opacity: 0.8;
    }
    .loader.small { 
        padding:30px 0;
        position: relative;
        text-align: center;
    }
</style>                    {{else}}
                        {{#if error}}
                            <div class="alert alert-info">{{ error }}</div>
                        {{else}}
                            <div id="restaurantCalendar" class="calendar">
    <div class="line head clearfix">
        <div class="day">{{ calendar.breakfast[0].day_week_name }}</div>
        <div class="day">{{ calendar.breakfast[1].day_week_name }}</div>
        <div class="day">{{ calendar.breakfast[2].day_week_name }}</div>
        <div class="day">{{ calendar.breakfast[3].day_week_name }}</div>
        <div class="day">{{ calendar.breakfast[4].day_week_name }}</div>
        <div class="day">{{ calendar.breakfast[5].day_week_name }}</div>
        <div class="day">{{ calendar.breakfast[6].day_week_name }}</div>
    </div>
    <div class="line subhead clearfix">
        <div class="day">{{ calendar.breakfast[0].qtd_tables+' '+(calendar.breakfast[0].qtd_tables > 1 ? 'Mesas' : 'Mesa') }}</div>
        <div class="day">{{ calendar.breakfast[1].qtd_tables+' '+(calendar.breakfast[1].qtd_tables > 1 ? 'Mesas' : 'Mesa') }}</div>
        <div class="day">{{ calendar.breakfast[2].qtd_tables+' '+(calendar.breakfast[2].qtd_tables > 1 ? 'Mesas' : 'Mesa') }}</div>
        <div class="day">{{ calendar.breakfast[3].qtd_tables+' '+(calendar.breakfast[3].qtd_tables > 1 ? 'Mesas' : 'Mesa') }}</div>
        <div class="day">{{ calendar.breakfast[4].qtd_tables+' '+(calendar.breakfast[4].qtd_tables > 1 ? 'Mesas' : 'Mesa') }}</div>
        <div class="day">{{ calendar.breakfast[5].qtd_tables+' '+(calendar.breakfast[5].qtd_tables > 1 ? 'Mesas' : 'Mesa') }}</div>
        <div class="day">{{ calendar.breakfast[6].qtd_tables+' '+(calendar.breakfast[6].qtd_tables > 1 ? 'Mesas' : 'Mesa') }}</div>
    </div>
    {{#if filters.meal.indexOf("breakfast") > -1 || filters.meal.length == 0}}
        <div class="line breakfast clearfix">
            {{#each calendar.breakfast}}
                <a href="javascript:void(0)">
                    <div class="day {{ status }}">
                        <div>
                            {{ convertDay(date) }} {{ month_name }}
                            <div>
                                {{#if status != "closed"}}
                                    {{ hour }}
                                {{/if}}
                            </div>
                            {{ convertStatus(status, qtd_available) }}
                        </div>
                                                    <div class="popup_hidden">
                                <div class="title">
                                    {{#if status == "available"}}
                                        Reserve a primeira mesa e tenha 50% de desconto!
                                    {{elseif status == "soldout"}}
                                        Oops! Já foi reservado!
                                    {{else}}
                                        Primeira Mesa não operará neste dia.
                                    {{/if}}
                                </div>
                                <div class="content text-center">
                                    {{#if status == "available"}}
                                        <a target="_blank" href="/restaurante/{{ slug }}" class="btn">Conheça o Restaurante</a>
                                        <i style="display:block;font-style:normal">ou</i>
                                        <a href="/restaurante/{{ slug }}/reservar/{{ convertWeekDay(date) }}/cafe-da-manha" class="btn">Reserve Agora</a>
                                    {{else}}
                                        <div class="text">
                                            Mas você ainda pode reservar!
                                            <br>Ligue para <a href="tel:{{ phone }}" class="phone">{{ phone }}</a>
                                            {{#if website.length > 1}}, ou {{/if}}
                                        </div>
                                        {{#if website.length > 1}}
                                            <a href="http://{{ website }}" target="_blank" class="btn website">Entre no Site</a>
                                        {{/if}}
                                    {{/if}}
                                </div>
                            </div>
                                            </div>
                </a>
            {{/each}}
        </div>
    {{/if}}
    {{#if filters.meal.indexOf("lunch") > -1 || filters.meal.length == 0}}
        <div class="line lunch clearfix">
            {{#each calendar.lunch}}
                <a href="javascript:void(0)">
                    <div class="day {{ status }}">
                        <div>{{ convertDay(date) }} {{ month_name }}<div>{{#if status != "closed"}}{{ hour }}{{/if}}</div>{{ convertStatus(status, qtd_available) }}</div>
                                                    <div class="popup_hidden">
                                <div class="title">
                                    {{#if status == "available"}}
                                        Reserve a primeira mesa e tenha 50% de desconto!
                                    {{elseif status == "soldout"}}
                                        Oops! Já foi reservado!
                                    {{else}}
                                        Primeira Mesa não operará neste dia.
                                    {{/if}}
                                </div>
                                <div class="content text-center">
                                    {{#if status == "available"}}
                                        <a target="_blank" href="/restaurante/{{ slug }}" class="btn">Conheça o Restaurante</a>
                                        <i style="display:block;font-style:normal">ou</i>
                                        <a href="/restaurante/{{ slug }}/reservar/{{ convertWeekDay(date) }}/almoco" class="btn">Reserve Agora</a>
                                    {{else}}
                                        <div class="text">
                                            Mas você ainda pode reservar!
                                            <br>Ligue para <a href="tel:{{ phone }}" class="phone">{{ phone }}</a>
                                            {{#if website.length > 1}}, ou {{/if}}
                                        </div>
                                        {{#if website.length > 1}}
                                            <a href="http://{{ website }}" target="_blank" class="btn website">Entre no Site</a>
                                        {{/if}}
                                    {{/if}}
                                </div>
                            </div>
                                            </div>
                </a>
            {{/each}}
        </div>
    {{/if}}
    {{#if filters.meal.indexOf("dinner") > -1 || filters.meal.length == 0}}
        <div class="line dinner clearfix">
            {{#each calendar.dinner}}
                <a href="javascript:void(0)">
                    <div class="day {{ status }}">
                        <div>{{ convertDay(date) }} {{ month_name }}<div>{{#if status != "closed"}}{{ hour }}{{/if}}</div>{{ convertStatus(status, qtd_available) }}</div>
                                                    <div class="popup_hidden">
                                <div class="title">
                                    {{#if status == "available"}}
                                        Reserve a primeira mesa e tenha 50% de desconto!
                                    {{elseif status == "soldout"}}
                                        Oops! Já foi reservado!
                                    {{else}}
                                        Primeira Mesa não operará neste dia.
                                    {{/if}}
                                </div>
                                <div class="content text-center">
                                    {{#if status == "available"}}
                                        <a target="_blank" href="/restaurante/{{ slug }}" class="btn">Conheça o Restaurante</a>
                                        <i style="display:block;font-style:normal">ou</i>
                                        <a href="/restaurante/{{ slug }}/reservar/{{ convertWeekDay(date) }}/jantar" class="btn">Reserve Agora</a>
                                    {{else}}
                                        <div class="text">
                                            Mas você ainda pode reservar!
                                            <br>Ligue para <a href="tel:{{ phone }}" class="phone">{{ phone }}</a>
                                            {{#if website.length > 1}}, ou {{/if}}
                                        </div>
                                        {{#if website.length > 1}}
                                            <a href="http://{{ website }}" target="_blank" class="btn website">Entre no Site</a>
                                        {{/if}}
                                    {{/if}}
                                </div>
                            </div>
                                            </div>
                </a>
            {{/each}}
        </div>
    {{/if}}
</div>
<div class="swipe visible-xs visible-sm">← deslize o calendário →</div>                     {{/if}}
                    {{/if}}
                </script>
            </div>
        </div>
    </div>

What I wanted was to use file_get_contents with preg_match_all to search when I had class="day available , but I believe that it does not return the result because of JS , so I can not search.

Is this really the problem?

What other way can I make this query in the content of the page, using php ?

    
asked by anonymous 08.03.2018 / 21:00

1 answer

2

The solution to your problem is to use the browser's Network Inspector and study the API calls.

For example, on page:

https://www.primeiramesa.com.br/restaurante/container-burguer

We have the XHR requisition:

https://www.primeiramesa.com.br/api/v1/restaurant/calendar?slug=container-burguer

That returns a json with the information you want:

{
"error": false,
"calendar": {
    "breakfast": [
        {
            "date": "Thu, 08 Mar 2018 00:00:00 -0300",
            "hour": "00:00",
            "day_week_name": "QUI",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "closed"
        },
        {
            "date": "Fri, 09 Mar 2018 00:00:00 -0300",
            "hour": "00:00",
            "day_week_name": "SEX",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "closed"
        },
        {
            "date": "Sat, 10 Mar 2018 00:00:00 -0300",
            "hour": "00:00",
            "day_week_name": "SAB",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "closed"
        },
        {
            "date": "Sun, 11 Mar 2018 00:00:00 -0300",
            "hour": "00:00",
            "day_week_name": "DOM",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "closed"
        },
        {
            "date": "Mon, 12 Mar 2018 00:00:00 -0300",
            "hour": "00:00",
            "day_week_name": "SEG",
            "qtd_tables": "1",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "closed"
        },
        {
            "date": "Tue, 13 Mar 2018 00:00:00 -0300",
            "hour": "00:00",
            "day_week_name": "TER",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "closed"
        },
        {
            "date": "Wed, 14 Mar 2018 00:00:00 -0300",
            "hour": "00:00",
            "day_week_name": "QUA",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "closed"
        }
    ],
    "lunch": [
        {
            "date": "Thu, 08 Mar 2018 00:00:00 -0300",
            "hour": "00:00",
            "day_week_name": "QUI",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "closed"
        },
        {
            "date": "Fri, 09 Mar 2018 15:00:00 -0300",
            "hour": "15:00",
            "day_week_name": "SEX",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": "10",
            "status": "available"
        },
        {
            "date": "Sat, 10 Mar 2018 15:00:00 -0300",
            "hour": "15:00",
            "day_week_name": "SAB",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": "10",
            "status": "available"
        },
        {
            "date": "Sun, 11 Mar 2018 15:00:00 -0300",
            "hour": "15:00",
            "day_week_name": "DOM",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": "10",
            "status": "available"
        },
        {
            "date": "Mon, 12 Mar 2018 00:00:00 -0300",
            "hour": "00:00",
            "day_week_name": "SEG",
            "qtd_tables": "1",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "closed"
        },
        {
            "date": "Tue, 13 Mar 2018 00:00:00 -0300",
            "hour": "00:00",
            "day_week_name": "TER",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "closed"
        },
        {
            "date": "Wed, 14 Mar 2018 00:00:00 -0300",
            "hour": "00:00",
            "day_week_name": "QUA",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "closed"
        }
    ],
    "dinner": [
        {
            "date": "Thu, 08 Mar 2018 18:00:00 -0300",
            "hour": "18:00",
            "day_week_name": "QUI",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "timeout"
        },
        {
            "date": "Fri, 09 Mar 2018 17:00:00 -0300",
            "hour": "17:00",
            "day_week_name": "SEX",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": "10",
            "status": "available"
        },
        {
            "date": "Sat, 10 Mar 2018 17:00:00 -0300",
            "hour": "17:00",
            "day_week_name": "SAB",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": "10",
            "status": "available"
        },
        {
            "date": "Sun, 11 Mar 2018 17:00:00 -0300",
            "hour": "17:00",
            "day_week_name": "DOM",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": "10",
            "status": "available"
        },
        {
            "date": "Mon, 12 Mar 2018 00:00:00 -0300",
            "hour": "00:00",
            "day_week_name": "SEG",
            "qtd_tables": "1",
            "month_name": "MAR",
            "qtd_available": 0,
            "status": "closed"
        },
        {
            "date": "Tue, 13 Mar 2018 18:00:00 -0300",
            "hour": "18:00",
            "day_week_name": "TER",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": "10",
            "status": "available"
        },
        {
            "date": "Wed, 14 Mar 2018 18:00:00 -0300",
            "hour": "18:00",
            "day_week_name": "QUA",
            "qtd_tables": "10",
            "month_name": "MAR",
            "qtd_available": "10",
            "status": "available"
        }
    ]
}

}

In this case one:

$dados = json_decode(file_get_contents('https://www.primeiramesa.com.br/api/v1/restaurant/calendar?slug=container-burguer'), true);
print_r($dados);

Do what you want.

    
09.03.2018 / 00:49