Search code examples
google-chromewebweb-crawlerpostmanrcrawler

Website crawling: responses are different for postman and browser


I want to crawl the site https://www.ups.com/de/de/shipping/surcharges/fuel-surcharges.page. There, the company is giving all fuel surcharges they are adding to invoice amounts. I need the information to correctly calculate some costs. Unfortunately, UPS is currently not willing to send me the data in a readable format on a regular basis. Thus, I thought about crawling the website and getting the information by myself.

Unfortunately, when using postman or my crawling tool rcrawler, the GET request to the site hides the data tables. How could I trick the site to return all the data as it does when using chrome browser?

For example, the standard tier costs table looks like this in postman (containing just the headlines of the columns but no values):

<div class="ups-contentBlock_wrap clearfix">
    <p>Der Standard Service Treibstoffzuschlag gilt f&uuml;r
        alle UPS Standard Sendungen. Die &Auml;nderungen des
        auf den n&auml;chsten Cent gerundeten Zuschlages
        werden am Montag jeder Woche wirksam und basieren
        auf den von der Generaldirektion der
        Europ&auml;ischen Kommission (ECDG) festgesetzten
        Verbraucherpreisen f&uuml;r Dieselkraftstoffe,
        einschliesslich der Z&ouml;lle und Steuern zweier
        Vorwochen. Der Zuschlag f&uuml;r die Woche vom 6.
        Februar 2017 basiert auf dem Dieselkraftstoffpreis
        f&uuml;r die Woche vom 23. Januar 2017.
        W&ouml;chentliche Aktualisierungen werden von der
        Generaldirektion Energie der Europ&auml;ischen
        Kommission (ECDG) f&uuml;r Energie und Verkehr im
        &Ouml;lbericht ver&ouml;ffentlicht.</p>
    <p>Der Treibstoffzuschlag f&uuml;r den UPS
        Standard-Service basiert auf den Angaben in der
        folgenden Tabelle:</p>
    <div class="ups-table fuel-surcharge">
        <table id="DieselFuelPriceStandardFuelSurcharge">
            <thead>
                <tr>
                    <th colspan="3">Dieseltreibstoffpreis
                        (EUR pro 1.000 Liter)</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <th>
                        <p>Mindestens</p>
                    </th>
                    <th>
                        <p>Aber weniger als</p>
                    </th>
                    <th>
                        <p>Zuschlag</p>
                    </th>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<div class="ups-contentBlock_wrap clearfix">
    <p>Die H&ouml;he des Treibstoffzuschlags kann sich ohne
        vorhergehende Ank&uuml;ndigung &auml;ndern. Wenn der
        Treibstoffzuschlag &uuml;ber 14,50% ansteigt oder es
        zu &Auml;nderungen der Grenzwerte kommt, wird die
        obenstehende &Uuml;bersicht aktualisiert. Ungeachtet
        der durch die ECDG genannten durchschnittlichen
        Treibstoffpreise oder der obenstehenden
        &Uuml;bersicht werden die aktuellen oben
        ver&ouml;ffentlichen prozentualen Anteile des
        Treibstoffzuschlages f&uuml;r die festgelegten
        Zeitr&auml;ume ber&uuml;cksichtigt.</p>
</div>

Comparing this with the browser result shows the problem.


Solution

  • You are just naively downloading the website source.

    If you open developer tools in your browser (usually F12) and open the Network tab, and reload the page, you will see all the requests that are made.

    You will notice several javascript files, and somewhere in that list you will also see a file named de.json. If you look at the response form that request, you will see all the rates displayed as json.

    One of the javascript files parses this and displays this data in a table, in your browser. Postman does not have a javascript interpreter; actually it does, but it is not used same as a web browser. So requesting the entire page will not show you this data.

    However, if you GET https://www.ups.com/assets/resources/fuel-surcharge/de.json you will get the data you are after.