Author Topic: Reading Text From a Webpage  (Read 631 times)

Let's say I have some text in a webpage, or a file on Dropbox, such as this:
https://dl.dropboxusercontent.com/u/63039269/test.txt

Is there a way by which I could read the text in that file from Blockland?
Notes:
Line-By-Line is not necessary, but would be appreciated.
Of course, the output should be a string.

Thanks.

So if you want to grab something from a website, you can use something like this:


function SeeContents(%website,%directory)
{
   %this = new TCPObject(SomeTCPObject)
   {
      host = %website; //Only have a basic website, don't have something like www.google.com/search, just www.google.com
   };
   %this.port = 80;
   if(!strLen(%directory))
      %directory = "index.html";
   %this.directory = %directory;
   %this.connect(%this.host @ ":" @ %this.port);
}

function SomeTCPObject::onConnected(%this)
{
   %this.send("GET /" @ %this.directory @ " HTTP/1.0\r\nHost: " @ %this.host @ "\r\n\r\n");
}

function SomeTCPObject::onLine(%this,%line)
{
   echo(%line); //This should echo each line into the console
}


So then your thing would be something like SeeContents("dl.dropboxusercontent.com","u/63039269/test.txt");

If you want simpler code, you can use a HTTPObject instead.


new HTTPObject(dropboxxy);
dropboxxy.get("dl.dropboxusercontent.com:80","/u/63039269/test.txt");


function dropboxxy::onLine(%this,%line) //called on every ::get execution
{
   //parse %line
}




if you prefer reading it like this-
Code: [Select]
new HTTPObject(dropboxxy);
dropboxxy.get("dl.dropboxusercontent.com:80","/u/63039269/test.txt");


function dropboxxy::onLine(%this,%line) //called on every ::get execution
{
//parse %line
}



If you'd like, use HTTPObjects for simple web requests. Do not attempt to create sessions with them or anything. For quick and dirty uses like these, they are fine.
« Last Edit: March 08, 2014, 08:23:25 PM by Pacnet »

Thanks, this is exactly what I needed.