Advertisement
Guest User

C# imbd scraper

a guest
Jun 24th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. namespace imdb_parser_2
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             StreamReader sr = new StreamReader("nagydb.txt");
  8.             StreamWriter sw = new StreamWriter("datacollection.txt");
  9.             sw.AutoFlush = true;
  10.            
  11.             //Számláló
  12.             int counter = 0;
  13.  
  14.             //Film linkjének beolvasása
  15.             string link = sr.ReadLine();
  16.  
  17.             while(!sr.EndOfStream)
  18.             {
  19.                 //Előkészítjük az adott filmet az adatok befogadására
  20.                 var CurrentMovie = new movie();
  21.  
  22.                 //Beírjuk a filmbe az adatokat
  23.                 CurrentMovie.SetData(link);
  24.  
  25.                 sw.WriteLine(WebUtility.HtmlDecode(CurrentMovie.title) + ";" + CurrentMovie.plot + ";" + CurrentMovie.img);
  26.                 counter++;
  27.                 Console.WriteLine(counter);
  28.  
  29.                 link = sr.ReadLine();
  30.             }
  31.  
  32.         }
  33.     }
  34.  
  35.     public class movie
  36.     {
  37.         // Field
  38.         public string title;
  39.         public string plot;
  40.         public string year;
  41.         public string link;
  42.         public string img;
  43.  
  44.         // Constructor
  45.         public movie()
  46.         {
  47.             title = "unknown title";
  48.             plot = "no plot";
  49.             year = "no year";
  50.         }
  51.         // Method
  52.         public void SetData(string link)
  53.         {
  54.             try
  55.             {
  56.                 IMDb imdb_movie = new IMDb(link, false);
  57.                 title = imdb_movie.Title;
  58.                 plot  = WebUtility.HtmlDecode(imdb_movie.Plot);
  59.                 year  = WebUtility.HtmlDecode(imdb_movie.Year);
  60.                 img   = WebUtility.HtmlDecode(imdb_movie.Poster);
  61.             }
  62.  
  63.             catch (Exception e)
  64.             {
  65.                 Console.WriteLine("Hiba történt, folytatom!");
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement