Search for values in the page source code

Asked

Viewed 245 times

1

There’s this one website, which generates a table of reserved and available tables without login:

inserir a descrição da imagem aqui

On inspection, you can see the style of the div (e.g..: class="day closed"):

inserir a descrição da imagem aqui

But the source code shows this:

<div id="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 the file_get_contents with the preg_match_all to search when it had class="day available, but I believe that it does not bring the result on account of the JS, and thus having no way to research.

That’s really the problem ?

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

  • You can inform the website link?

  • I added it to "website" !

1 answer

2


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

For example, on the page:

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

We have the XHR request:

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 that case a:

$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.

  • Caraca, I didn’t know it ! I looked here and did the following: I walked the network and found the calendar?slug=container-burguer, which would be this API. Just so I understand if that’s exactly it, you did it too or in the source code, something points more directly ?

  • There is nothing in the page code, just note that Slug=container-Burger is the end of the page URL, which is easy to extract with an end(explode('/', 'https://www.primeiramesa.com.br/restaurante/container-burguer')); That is, you do not need the source code of the restaurant page, only the same address.

Browser other questions tagged

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