Zubrag.com
August 23, 2019, 09:14:56 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Accessing Alexa thumbnails  (Read 8507 times)
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« on: February 19, 2007, 07:22:28 AM »

In this article you'll see examples of using proxy, proxy authentication, scrapping, and parsing data using regular expressions.

Note: this script was created for educational purposes only. Alexa provides really cheap service (1000 images for $0.20), so please do not overuse use this script, and use in educational purposes only.

1. Save php code provided below in some php file, for example alexa_image.php.
2. Create cron job to run this script each maybe 5 minutes (as long as session does not expire). It will create file named image_url.txt, containing sample image url (template) with recent session id.
3. Create another script, where you will show images. Read image string from image_url.txt, replace cnn.com with with your desired site, and use it in img tag, like:

<img src="here image string you read from file">

There is Size=Large parameter, which can be tuned to alter image size (Large or Small).

Tip: you could generate thumbnails yourself on Windows server.

<?php

// use proxy?
$use_proxy = false;

// following only needed when using proxy:
$proxy_auth = true; // proxy authentication?
$proxy_name = '23.23.23.23'; // proxy ip
$proxy_port = 8080;
$proxy_user = "user";
$proxy_pass = "password";

// url to grab alexa image path from
$url = "http://www.alexa.com/data/details/traffic_details?&range=1y&size=large&compare_sites=&url=www.cnn.com";

if ($use_proxy) {
  $fp = fsockopen($proxy_name, $proxy_port);
  if (!$fp) {return false;}
  fputs($fp, "GET $url HTTP/1.0\r\nHost: $proxy_name\r\n");
  if ($proxy_auth)
    fputs($fp, "Proxy-Authorization: Basic " . base64_encode ("$proxy_user:$proxy_pass") . "\r\n");
  fputs($fp, "\r\n");
}
else {
  $tmp = parse_url($url);
  if (empty($tmp['port'])) {
    $tmp['port'] = 80;
  }
  $fp = fsockopen($tmp['host'], $tmp['port'], $errno, $errstr);

  $path = $tmp['path'];
  if (isset($tmp['query'])) { $path .= "?$tmp[query]"; }
  fputs($fp, "GET $path HTTP/1.0\r\nHost: $tmp[host]:$tmp[port]\r\n\r\n");
}

while(!feof($fp)) {
  $content = fread($fp,4096);
  $found = preg_match('/(http:\/\/ast.amazonaws.com\/Xino[^"]*)/', $content, $match);
  if ($found) {
    $content = $match[1];
    break;
  }
  else {
    $content = '';
  }
}
fclose($fp);

// save image url to file
$fp = fopen("image_url.txt",'w+');
fputs($fp,$content);
fclose($fp);

?>

Logged
albertjooger
Newbie
*
Posts: 9


« Reply #1 on: April 13, 2011, 08:30:11 AM »

I have observed that Alexa ranking is not real. They based their ranking on the number of views not on the number of visits. Secondly, the 90% of the traffic we get for our websites is from Google, so there is no point to waste time on flawed Alexa ranking.
Logged

P
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC