Not able to see the data of url by curl + php

Discussion in 'PHP' started by zappak, Mar 17, 2011.

  1. #1
    hello again,

    i'm trying to fetch data by curl + php from one site.. but not able to do coz there is damn too much privacy i guess..

    here the code ...
    <?php
    
    
    $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL, 'http://www.factual.com/t/bi0eJZ/US_POI_and_Business_Listings_Beta');
              curl_setopt($ch, CURLOPT_HEADER, 0);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
              curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
              curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
              curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12");
              $data = curl_exec($ch);
              curl_close($ch);
              echo $data;
    
    ?>
    PHP:
    anyone know how to fetch that??

    pls mode remove that if break rule or terms
     
    zappak, Mar 17, 2011 IP
  2. Automagick

    Automagick Greenhorn

    Messages:
    22
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    23
    #2
    Add this option and try again:

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

    This will get the contents in case the page you request makes header redirections.
     
    Automagick, Mar 17, 2011 IP
  3. zappak

    zappak Active Member

    Messages:
    366
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    80
    #3
    hey there isn't redirect problem.. there is prob with fetching data..

    just try to on url and get known..

    thx for reply though.. ;)

     
    zappak, Mar 17, 2011 IP
  4. lordspace

    lordspace Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    it seems that the content loads with ajax/iframes.
    You have to use a different option to simulate browser because it has to support ajax/js.
    this could be done using Perl/PHP under Windows that starts Firefox/IE

    The HTML code looks complex so I'd ask that site for a CSV file.
    You might have to pay extra for this but it will save you time in the long run because even though you could hire somebody to build you a parser you'll have to constantly check if the HTML code of the page you're parsing has changed.
     
    lordspace, Mar 17, 2011 IP
  5. zappak

    zappak Active Member

    Messages:
    366
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    80
    #5
    yup.

    I got the solution by curl and php but I'm getting result very complex..

    I must need to solve that data now..

    thx for reply though

    anyone has anyother solution.. there is prob with posting data and getting back data which I want from...



     
    zappak, Mar 18, 2011 IP
  6. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #6
    I'm not sure if I'm sending you on the right track, but here's something to look at, it still throws an error but you might find a work around quicker.

    
    <?php 
    
    
    
    
    $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL, 'http://www.factual.com/t/bi0eJZ/US_POI_and_Business_Listings_Beta');
              curl_setopt($ch, CURLOPT_HEADER, 0);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
              curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
              curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
              curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12");
              $data = curl_exec($ch);
              curl_close($ch);
    
    
    $data = preg_replace('#link href="/#','link href="http://www.factual.com/',$data);
    $data = preg_replace('#script src="/#','script src="http://www.factual.com/',$data);
    $data = preg_replace('#a href="/topics#','a href="http://www.factual.com/topics',$data);
    $data = preg_replace('#action="/topics/find#','action="http://www.factual.com/topics/find',$data);         
               
              echo $data;
    
    ?>
    
    PHP:
     
    MyVodaFone, Mar 18, 2011 IP
  7. zappak

    zappak Active Member

    Messages:
    366
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    80
    #7
    thx for reply mate,

    that's not fetching data yet,

    it's highly protected lol..

     
    zappak, Mar 18, 2011 IP