google.cs

来自「用C#编写的一个款搜索engine的源代码!摘自<Visual c#200」· CS 代码 · 共 72 行

CS
72
字号
using System;
using System.Collections;
using SECompare.Config;
using SECompare.Structure;

namespace SECompare.SearchAPI
{
	/// <summary>
	/// Summary description for Google.
	/// </summary>
	public class Google
	{
		public Google()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		/// <summary>
		/// Crawl and save results.
		/// </summary>
		/// <param name="words"></param>
		/// <param name="start"></param>
		/// <param name="maxResults"></param>
		/// <returns></returns>
		public static bool Crawl(String words,int start,int maxResults)
		{
			//If start>1000
			if(start>1000) 
				return false;
			ArrayList results = GoogleParser.Parser.Run(words,start,maxResults);
			//If no returns, there is no results.
			if(results==null||results.Count==0)
				return false;
			//If returned results is too little, there are no more results.
			if(results.Count<(maxResults*0.9)&&start>10) 
				return false; 
			for(int i=0;i<results.Count;i++)
			{
				GoogleParser.Parser.Record record = (GoogleParser.Parser.Record)results[i];
				QueryRecord r = new QueryRecord(words,EngineSet.Google,(start+i).ToString(),
					record.Title,record.URL,record.Snippet);
				r.Save();
			}
			
			//Write Log file
            Config.Log.Append("Google Saved:" + words + "[" + start.ToString() + "-" + (start + results.Count - 1).ToString() + "]");		
			return true;
		}

		public static QueryRecord[] Parse(String html,String words,int start)
		{
			ArrayList results = GoogleParser.Parser.Run(html);
			//If no returns, there is no results.
			if(results==null||results.Count==0)
				return null;
			//Construct return value
			QueryRecord[] ret = new QueryRecord[results.Count];
			for(int i=0;i<results.Count;i++)
			{
				GoogleParser.Parser.Record record = (GoogleParser.Parser.Record)results[i];
				ret[i] = new QueryRecord(words,EngineSet.Google,(start+i).ToString(),
					record.Title,record.URL,record.Snippet);
			}
			return ret;
		}


	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?