我必须从浏览器的选项卡中获取标题并将其存储在字符串变量中。我正在研究 Ranorex 自动化工具并使用 C# 作为我的脚本语言。
谢谢,穆迪
我必须从浏览器的选项卡中获取标题并将其存储在字符串变量中。我正在研究 Ranorex 自动化工具并使用 C# 作为我的脚本语言。
谢谢,穆迪
也许是这样的!???
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 "";
}
}
}
}