C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet1041/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   1037   1038   1039   1040   1041   1042   1043   1044   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

href="http

 hypertext command are found. Relative links are not used. Second, there is 

no way to go back to an earlier link. Third, it displays only the links and no surrounding 

content. Despite these limitations, the skeleton is fully functional, and you will have no 

trouble enhancing MiniCrawler to perform other tasks. In fact, adding features to MiniCrawler 

is a good way to learn more about the networking classes and networking in general.

Here is the entire code for MiniCrawler:

/* MiniCrawler: A skeletal Web crawler.

   Usage:

     To start crawling, specify a starting

     URI on the command line. For example,

     to start at McGraw-Hill.com, use this

     command line:

       MiniCrawler http://McGraw-Hill.com

*/

using System;



using System.Net;

using System.IO;

class MiniCrawler {

  // Find a link in a content string.

  static string FindLink(string htmlstr,

                         ref int startloc) {

    int i;

    int start, end;

    string uri = null;

    string lowcasestr = htmlstr.ToLower();

    i = lowcasestr.IndexOf("href=\"http", startloc);

    if(i != -1) {

      start = htmlstr.IndexOf(‘"’, i) + 1;

      end = htmlstr.IndexOf(‘"’, start);

      uri = htmlstr.Substring(start, end-start);

      startloc = end;

    }

www.freepdf-books.com




840

 

P a r t   I I :  



E x p l o r i n g   t h e   C #   L i b r a r y

    return uri;

  }

  static void Main(string[] args) {



    string link = null;

    string str;

    string answer;

    int curloc; // holds current location in response

    if(args.Length != 1) {

      Console.WriteLine("Usage: MiniCrawler ");

      return ;

    }


    string uristr = args[0]; // holds current URI

    try {

      do {

        Console.WriteLine("Linking to " + uristr);

        // Create a WebRequest to the specified URI.

        HttpWebRequest req = (HttpWebRequest)

               WebRequest.Create(uristr);

        uristr = null; // disallow further use of this URI

        // Send that request and return the response.

        HttpWebResponse resp = (HttpWebResponse)

               req.GetResponse();

        // From the response, obtain an input stream.

        Stream istrm = resp.GetResponseStream();

        // Wrap the input stream in a StreamReader.

        StreamReader rdr = new StreamReader(istrm);

        // Read in the entire page.

        str = rdr.ReadToEnd();

        curloc = 0;

        do {

          // Find the next URI to link to.

          link = FindLink(str, ref curloc);

          if(link != null) {

            Console.WriteLine("Link found: " + link);

            Console.Write("Link, More, Quit?");

            answer = Console.ReadLine();

            if(string.Compare(answer, "L", true) == 0) {

              uristr = string.Copy(link);

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   1037   1038   1039   1040   1041   1042   1043   1044   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish