...

View Full Version : Scripting



arthur92710
11-03-2008, 07:18 AM
The script on this http://forre.st/storage page is python(source at the bottom), but I dont know it and dont really have time to learn it right now. Is there a way to make a similar script but with html or php? I am pretty good with html and know some php.
Thanks for any help.

itsallkizza
11-03-2008, 07:23 AM
Ya absolutely.

You can do the graph in Javascript and CSS (or Flash). You'll only need php if you want to store the data in a SQL database (which would be wise) or if you're grabbing the data from another website.

The Python script is creating a nifty little image, which is nice for data encapsulation, but really uneccessary unless you're trying to protect your data.

arthur92710
11-03-2008, 07:33 AM
WOW 5 min response time! Thats awsome, I have never seen that before! The best part is that my question wasn't denied!

I just have one question, how can I automatically grab the prices from the site?

itsallkizza
11-03-2008, 07:41 AM
Hm... you mean the prices listed under each image? Well assuming they don't have an API they're willing to let you use, then one sloppy way to do that is use PHP/ASP to grab the page's source code and parse through it's DOM.

If you need any help with that let me know.

arthur92710
11-03-2008, 07:43 PM
Hum, that sounds not to hard, Ill try it out and see how far I can get.
Thanks.

itsallkizza
11-03-2008, 07:54 PM
Here's a quick php API for you:


<?php
$url = $_GET["url"] ? $_GET["url"] : null;
if ($url) include($url);
else echo("null");
?>

arthur92710
11-03-2008, 08:11 PM
Uh, Im sorry
Can you explain how it works?

itsallkizza
11-03-2008, 08:44 PM
Open up a blank txt document and copy and paste that php snippet into it, save it as something like "get_src.php"

Upload that to your server (I have a temporary example for you: http://ebonyaura.com/get_src.php) and that can serve as your page source API.

get_src.php accepts a single input called url and outputs that URL's source code. For example, "http://ebonyaura.com/get_src.php?url=http://www.google.com" will display google's homepage.

Now all you need to do is call get_src.php from your project's page using Javascript (if you like), something like this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<style type="text/css">
</style>
<script type="text/javascript">
<!--
function getXMLHttp()
{
var xmlHttp;
try // Firefox, Opera 8.0+, Safari
{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
// Internet Explorer
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}

function getAnotherPage(url)
{
var xml_http = getXMLHttp();
if (xml_http)
{
xml_http.onreadystatechange = function()
{
if (this.readyState == 4)
{
doYourStuff(this);
}
}
xml_http.open("GET","http://ebonyaura.com/get_src.php?url="+url,true);
xml_http.send(null);
}
}

function doYourStuff(xml_http)
{
alert(xml_http.responseText);
}
// -->
</script>
</head>
<body>

<input type="button" value="click me" onclick="getAnotherPage('http://www.google.com');" />

</body>
</html>


Of course you'll need to change ebonyaura.com to your domain, but here's a working example of the page I just typed up for you: http://ebonyaura.com/project.html

Altogether, this is essentially a fast workaround for the same-origin policy constraint on ajax.

arthur92710
11-03-2008, 09:16 PM
Hum, that does not want to work on my server. I replaced ebonyaura.com to my domain.
Ill check on something.

And I have a question why is the "<input type="button" value="click me" onclick="getAnotherPage('http://www.google.com');" />"
http://www.google.com?

itsallkizza
11-04-2008, 03:04 AM
The whole point of that JS function and PHP api is that you can input any url any where, regardless of same-origin security sandbox issues.

google.com is just an example



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum