[ale] CLI way to interact with JavaScript URL?
Mike Harrison
meuon at geeklabs.com
Tue Dec 2 19:50:45 EST 2008
On Tue, 2 Dec 2008, Jeff Lightner wrote:
> OK it's been about 3 years since I last looked into this. Back then
> the answer seemed to be there wasn't a way to do it with tools like
> lynx, curl and wget or any other CLI browser.
If you are a PHP hack like I am, I'd possibly start off by using:
"class.XMLHttpRequest.php" from a PHP Script from a command line.
I use such tools for all kinds of things... it fakes JavaScript
Ajax style calls, but also works for other things.
Google for it. If you can't find it, I have one I use, but it's pretty
common use for "Web 2.0" code, and I abuse it a lot for things.
Example:
function translate($incoming, $lang) {
require_once ('class.XMLHttpRequest.php');
$ajax = new XMLHttpRequest();
$ajax->open("POST", "http://www.google.com/translate_t?langpair=$lang");
$ajax->send("langpair=$lang&text=$incoming");
if ($ajax->status == 200) {
$result = $ajax->responseText;
preg_match_all("#dir=\"ltr\">(.*?)</div#", $result, $trans);
$translation = $trans[1][0];
return "$translation";
} else {
echo "ERROR: $ajax->status";
};
} ;
More information about the Ale
mailing list