我需要输入值并进行搜索链接,找到html中的单词和链接。
如果存在单词,则显示消息并继续在找到的链接中监视该单词并显示消息,如果不存在,则显示消息并继续在找到的油墨中搜索单词。
单词和起始网址是从输入中获取的。
我实现了从链接的html中获取单词并显示消息的方法 这是它的代码。
[HttpPost]
public JsonResult SearchWord([FromBody] RequestModel model){
string result;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(model.adress);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null;
if (response.CharacterSet == null)
{
readStream = new StreamReader(receiveStream);
}
else
{
readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
}
string data = readStream.ReadToEnd();
string pattern = model.word;
// Instantiate the regular expression object.
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
// Match the regular expression pattern against your html data.
Match m = r.Match(data);
if (m.Success)
{
result = "Word "+model.word+" finded in "+ model.adress;
}
else{
result = "Word not finded";
}
response.Close();
readStream.Close();
return Json(result);
}
如何获取所有链接并继续在其中搜索单词?