1
<?php
        include_once('simple_html_dom.php');

        $veri = file_get_html("http://apps.istanbulsaglik.gov.tr/Eczane");


        preg_match_all('@<a href="(.*?)" class="ilce-link" data-value="(.*?)" 
        data-ilcename="(.*?)" data-title="(.*?)" id="ilce" title="(.*?)"><i 
        class="fa fa-dot-circle-o"></i>(.*?)</a>@si',$veri,$baslik);
        $length = count($baslik[4]);

        for ($i = 0; $i < $length; $i++) {
           echo $baslik[4][$i];
           echo "</br>";
        }

        preg_match_all('@<table class="table ilce-nobet-detay" id="ilce-nobet-detay">(.*?)</table>@si',$veri,$adres);

        echo $adres[1][1];
    ?>

In this link; http://apps.istanbulsaglik.gov.tr/Eczane I can not get the right side elements that will be listed under "Eczaneler".

Because I need to click any of left side elements then, I can see them. What I want to do is getting that elements in my web crawler. The main problem is how can I make my crawler click? without clicking I can not see any data. If I can make it click, then I can take the data from html source. If not my crawler will always return empty.

1 Answer 1

1

If you use any browser's inspector on http://apps.istanbulsaglik.gov.tr/Eczane link, you will see that each link in İlçeler column has a data-value and binded to a click event:

the page Javascript code:

$(function () {
    $(".ilce-link").on("click", function (parameters) {
        var title = $(this).data("title").toUpperCase();
        var id = $(this).data("value");
        var request = $.ajax({
            url: "/Eczane/nobetci",
            method: "POST",
            data: { "id": id, "token": "aa416735d12fd44b" },
            dataType: "html"
        });
        request.done(function (data) {
            $("#nobet").empty(" ");
            $("#nobet").html('<i class="fa fa-spinner fa-spin"></i>');
            $("#nobet").html(data);
            document.title = "06-11-2017 TARİHİNDEKİ " + title + " İLEÇSİNDEKİ NÖBETÇİ ECZANE LİSTESİ";
        });
    });
});

This code means that when you click on any link in the left column, the script will create a post request by AJAX to this url: http://apps.istanbulsaglik.gov.tr/Eczane/nobetci with an id and a token.

So the idea is to directly use this url and post data, you can get the id from the link element and the token from the js code on the first page, and then use CURL PHP to post these data.

Here is an example using CURL post:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://apps.istanbulsaglik.gov.tr/Eczane/nobetci");
curl_setopt($ch, CURLOPT_POST, 1);
// you can use preg_match_all to retrieve the id and the token from the first page
curl_setopt($ch, CURLOPT_POSTFIELDS, "id=$id&token=$token");

$output = curl_exec ($ch);

curl_close ($ch);
Sign up to request clarification or add additional context in comments.

3 Comments

What I understand from your answer is, I will find id and the token with preg_match_all and i will initialize them into $id and $token. What I wonder is what will this $output variable give me ?
I think, I don't need token, because it's automatically generated in script. But when I call the Curl function only with "id" it gives me runtime error as you can see when you directly enter the link = apps.istanbulsaglik.gov.tr/Eczane/nobetci
You have to create 2 Curl requests, the first one to retrieve the token from the page http://apps.istanbulsaglik.gov.tr/Eczane and the second to make a post request to http://apps.istanbulsaglik.gov.tr/Eczane/nobetci using the token that you already take from the first page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.