C# Crawler
Sagiv Hadaya is crawling in C#...just for fun




 

The Playboy Downloader...

Lets Build an automatic downloader...ha?

well, first for that example, lets look at a site first...now pay attention, this site is for adults,

http://rosbif.free.fr/playboy/

you enter your month and year of birth and recieve a lovely .jpg picture of Playboy playmate of that exact date. now be honest, after entering your date, you must have entered couple of other dates right? and you wished you could automate that right?

well, thats the fun (as i always say) lets build that downloader.

So, i dont know if you have noticed, but each picture contains an equal file name signature - "yyyy_mm.jpg", where yyyy stands for the year, and mm stands for the month.

If we search the .NET Class libraries deeply enough, we will stumble into a lovely east class named: 'System.Net.WebClient'.

WebClient has a simple method called 'DownloadFile' which recieves as parameters the URL+file location and the local file destination.

like:

DownloadFile("http://rosbif.free.fr/playboy/img/1975_09.jpg","my1975.jpg");

now all that is left, after that information is to create that cute application...

we will create two integers for the year and month, and set them to the first picture available (after i checked, it seems that Dec 53 is the first playmate).

int filenamey=1953; /*file name year*/

int filenamem=12; /*file name month*/

the url: string url=@"http://rosbif.free.fr/playboy/img/"; /*the main address*/

and the class: System.Net.WebClient wc= new System.Net.WebClient(); /*a webclient object*/

 

Now, lets create the loop itself.

while(!((2002==filenamey)&&(8==filenamem))) /*until aug 2002*/

{

          try

             {

              System.Console.WriteLine("Downloading..." +

              filenamey.ToString() +

              "_" + filenamem.ToString()+ ".jpg");

              /*adding a "0" to the file name month

              if month is smaller then 9*/

              if (filenamem>9)

              wc.DownloadFile(url+filenamey.ToString() +

               "_" + filenamem.ToString() +

               ".jpg",filenamey.ToString() +

               "_" + filenamem.ToString() + ".jpg");

               else wc.DownloadFile(url+filenamey.ToString() +

               "_0" + filenamem.ToString() +

               ".jpg",filenamey.ToString() +

               "_0" + filenamem.ToString() + ".jpg");

             }

         catch(Exception exp)

        {

       }

}

 

thats about it, thats how easy it is. now, for the complete application click here

 


Click here to visit the Radio UserLand website.
Click to see the XML version of this web page.
Click here to send an email to the editor of this weblog.
© Copyright 2002 Sagiv Hadaya.
Last update: 10/11/2002; 2:04:55 AM.