查找word操作(支持多关键字查找)
Posted kamishiroshinchi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查找word操作(支持多关键字查找)相关的知识,希望对你有一定的参考价值。
1 using System; 2 using System.Net; 3 using System.IO; 4 using System.Text; 5 using System.Text.RegularExpressions; 6 using System.Net.Security; 7 using System.Security.Cryptography.X509Certificates; 8 using System.Collections; 9 10 namespace ConsoleApp1 11 { 12 13 class Program 14 { 15 public static string DoRequest(string Url, string cookieStr) 16 { 17 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); 18 request.Timeout = 1000 * 900; 19 request.Headers.Add(HttpRequestHeader.Cookie, cookieStr); 20 request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/31.0.1650.63 Safari/537.36"; 21 ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;// SecurityProtocolType.Tls1.2; 22 string back = ""; 23 try 24 { 25 WebResponse response = request.GetResponse(); 26 StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8); 27 back = reader.ReadToEnd(); 28 reader.Close(); 29 reader.Dispose(); 30 response.Close(); 31 } 32 catch (Exception ex) 33 { 34 back = ex.Message; 35 } 36 return back; 37 } 38 39 static void Main(string[] args) 40 { 41 Console.WriteLine("请输入关键字数目"); 42 int num = int.Parse(Console.ReadLine()); 43 ArrayList keywords = new ArrayList(); 44 for (int i = 0; i < num; i++) 45 { 46 Console.WriteLine("请输入第" + (i + 1).ToString() + "个关键字而后输入回车"); 47 keywords.Add(Console.ReadLine()); 48 } 49 string cookie = ""; 50 for (int i = 1; i < 64; i++) 51 { 52 string url = "https://www.php.cn/topic/word?p=" + i.ToString(); 53 string str = DoRequest(url, cookie); 54 bool canPass = true; 55 foreach (Object obj in keywords) 56 if (str.IndexOf(obj.ToString()) == -1) 57 { 58 canPass = false; 59 break; 60 } 61 if (canPass) 62 Console.WriteLine(url); 63 } 64 Console.WriteLine("检索完毕"); 65 Console.ReadLine(); 66 } 67 } 68 }
以上是关于查找word操作(支持多关键字查找)的主要内容,如果未能解决你的问题,请参考以下文章