Skip to content
Advertisement

PHP file_get_contents booking.com Site

I try to get a booking.com page from a hotel to fetch the prices afterwards with regex. The problem is the following:

I call file_get_contents with parameter like checkin and checkout (file_get_contents("/hotel/at/myhotel.html?checkin=2017-10-12&checkout=2017-10-13")) dates so that the prices are shown to the visitor. If I watch the source code in the browser I see the entry:

JavaScript

If I echo the string from file_get_contents the string looks like:

JavaScript

So all parameters that I passed to the url with file_get_contents are gone and therefore I couldn’t find any prices with my regex on the page …

Does anyone have a solution for this problem?

Advertisement

Answer

The webpage is not completely generated server-side, but it relies heavily on JavaScript after the HTML part loads. If you are looking for rendering the page as it looks in browser, I think you should use php curl instead of file_get_contents() for this kind of web scraping thing. I generated an automatic code for you from Postman (a google chrome extension / standalone desktop app) for your given url. The response contains the full url with params. See the image and I posted the code for you also.

enter image description here

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement