0

我必须从浏览器的选项卡中获取标题并将其存储在字符串变量中。我正在研究 Ranorex 自动化工具并使用 C# 作为我的脚本语言。

谢谢,穆迪

4

1 回答 1

0

也许是这样的!???

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
using System.Web.Http;
using System.Web;


 namespace HTMLConsoleRead1._0

{

class Program




 { 

    static void Main(string[] args)

     {

        string htmlTitle = File.ReadAllText("masterHTML.html");

        Console.WriteLine(GetTitle(htmlTitle));

        Console.ReadLine();

    }

    static string GetTitle(string file)
    {
        Match match = Regex.Match(file, @"<title>\s*(.+?)\s*</title>");
        if (match.Success)
        {
            return match.Groups[1].Value;
        }
        else
        {
            return "";
        }
    }
}

}

于 2014-02-20T03:35:19.623 回答