ActionScript 3 使用Actionscript获取谷歌网页排名
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 使用Actionscript获取谷歌网页排名相关的知识,希望对你有一定的参考价值。
package {
import flash.display.Sprite;
import flash.errors.*;
import flash.events.*;
import flash.net.Socket;
public class FetchPR extends Sprite
{
public const GOOGLE_MAGIC:Number = 0xE6359A60;
public var resultPR:Number = 0;
public var callback:Function;
private var sock:Socket;
public function zeroFill(a:Number, b:Number):Number
{
var z:Number = 0x80000000;
var sa:Number = a;
var sb:Number = b;
if (z & sa) {
sa = (sa>>1);
sa &= (~z);
sa |= 0x40000000;
sa = (sa>>(sb-1));
}
else {
sa = (sa>>sb);
}
return sa;
}
public function mixa(a:Number,b:Number,c:Number):Array
{
var sa:Number = a;
var sb:Number = b;
var sc:Number = c;
sa -= sb; sa -= sc; sa ^= (zeroFill(sc,13));
sb -= sc; sb -= sa; sb ^= (sa << 8);
sc -= sa; sc -= sb; sc ^= (zeroFill(sb,13));
sa -= sb; sa -= sc; sa ^= (zeroFill(sc,12));
sb -= sc; sb -= sa; sb ^= (sa<<16);
sc -= sa; sc -= sb; sc ^= (zeroFill(sb,5));
sa -= sb; sa -= sc; sa ^= (zeroFill(sc,3));
sb -= sc; sb -= sa; sb ^= (sa<<10);
sc -= sa; sc -= sb; sc ^= (zeroFill(sb,15));
return new Array(sa,sb,sc);
}
public function GoogleCH(url:Array, length:Number = 0, init:Number=GOOGLE_MAGIC):Number
{
if (length == 0) {
length = url.length;
}
var sa:Number = 0x9E3779B9;
var sb:Number = 0x9E3779B9;
var sc:Number = init;
var k:Number = 0;
var len:Number = length;
var mix:Array;
while(len >= 12) {
sa += (url[k+0] +(url[k+1]<<8) +(url[k+2]<<16) +(url[k+3]<<24));
sb += (url[k+4] +(url[k+5]<<8) +(url[k+6]<<16) +(url[k+7]<<24));
sc += (url[k+8] +(url[k+9]<<8) +(url[k+10]<<16)+(url[k+11]<<24));
mix = mixa(sa,sb,sc);
sa = mix[0]; sb = mix[1]; sc = mix[2];
k += 12;
len -= 12;
}
sc += length;
switch (len) {
case 11: sc+=(url[k+10]<<24);
case 10: sc+=(url[k+9]<<16);
case 9 : sc+=(url[k+8]<<8);
case 8 : sb+=(url[k+7]<<24);
case 7 : sb+=(url[k+6]<<16);
case 6 : sb+=(url[k+5]<<8);
case 5 : sb+=(url[k+4]);
case 4 : sa+=(url[k+3]<<24);
case 3 : sa+=(url[k+2]<<16);
case 2 : sa+=(url[k+1]<<8);
case 1 : sa+=(url[k+0]);
}
mix = mixa(sa,sb,sc);
return mix[2];
}
public function strord(str:String):Array
{
var result:Array = new Array();
for (var i:Number = 0; i < str.length; i++) {
result[i] = str.charCodeAt(i);
}
return result;
}
public function getPR(url:String):void
{
sock = new Socket("www.google.com", 80);
url = "info:" + url;
var ch:Number = GoogleCH(strord(url));
var urlstring:String = "/search?client=navclient-auto&ch=6" + ch + "&features=Rank&q=" + url;
sock.writeUTFBytes("GET " + urlstring + " HTTP/1.0
");
sock.writeUTFBytes("Host: toolbarqueries.google.com
");
sock.writeUTFBytes("User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114.9-big; Linux 2.6)
");
sock.writeUTFBytes("Connection: Close
");
sock.flush();
sock.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
}
private function socketDataHandler(event:ProgressEvent):void
{
var res:String = sock.readUTFBytes(sock.bytesAvailable);
var offset:Number = res.lastIndexOf("Rank");
res = res.substr(offset);
var result:Array = res.split(":");
resultPR = result[2];
callback.call(resultPR);
}
public function FetchPR()
{
}
}
}
以上是关于ActionScript 3 使用Actionscript获取谷歌网页排名的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3:字符命中测试对象,所有对象都在数组中
ActionScript 3 使用ActionScript 3暂停框架
ActionScript 3 clickTag使用ActionScript 3
ActionScript 3 全屏使用ActionScript 3