title: convert python scraping code in PHP to scrape instagram
body: <p>so here is working code of python to scrape the images from instagram </p>
  
  <pre><code>from __future__ import print_function
  import json, re, requests
  
  user = 'thefatfoxcamden'
  
  profile = 'https://www.instagram.com/' + user
  
  with requests.session() as s:
  s.headers['user-agent'] = 'Mozilla/5.0'
  
  end_cursor = ''
  for count in range(1, 3):
      print('PAGE: ', count)
      r = s.get(profile, params={'max_id': end_cursor})
  
      data = re.search(r'window._sharedData = (\{.+?});&lt;/script&gt;', r.text).group(1)
      j    = json.loads(data)
  
      for node in j['entry_data']['ProfilePage'][0]['user']['media']['nodes']: 
          if node['is_video']:
              page = 'https://www.instagram.com/p/' + node['code']
              r = s.get(page)
              url = re.search(r'"video_url": "([^"]+)"', r.text).group(1)
              print('VIDEO:', url)
          else:
              print('IMAGE:', node['display_src'])
  
      end_cursor = re.search(r'"end_cursor": "([^"]+)"', r.text).group(1)
  </code></pre>
  
  <p>Code is working awesome now i want to convert this code in PHP</p>
  
  <p>what i can get is right now that i can get only first loop </p>
  
  <p>which code is below </p>
  
  <pre><code>&lt;?php
  
  function scrape_insta($username) {
      $insta_source = file_get_contents('http://instagram.com/'.$username);
      $shards = explode('window._sharedData = ', $insta_source);
      $insta_json = explode(';&lt;/script&gt;', $shards[1]);
      $insta_array = json_decode($insta_json[0], TRUE);
      return $insta_array;
  }
  
   //Supply a username
   $my_account = 'thefatfoxcamden';
   $results_array = scrape_insta($my_account);
   $image_array= array();
  
    $dataList = ($results_array['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges']);
  
  
   for($i=0; $i&lt;count($dataList); $i++){
    if($dataList[$i]['node'][__typename]=='GraphImage'){
      //echo '&lt;img src="'.$dataList[$i]['node']['display_url'].'"&gt;&lt;/br&gt;';
      echo '&lt;img src="'.$dataList[$i]['node']['thumbnail_src'].'"&gt;&lt;/br&gt;';
  
     }
  }
  </code></pre>
  
  <p>above code is calling only for once </p>
  
  <p>i want to call in loop 3 times like the python code is doing.</p>
  
  <p>thanks in advance </p>