当前位置: 首页>>代码示例>>C#>>正文


C# ScriptEngine.Parse方法代码示例

本文整理汇总了C#中ScriptEngine.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.Parse方法的具体用法?C# ScriptEngine.Parse怎么用?C# ScriptEngine.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScriptEngine的用法示例。


在下文中一共展示了ScriptEngine.Parse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main()
    {
        const string videoUrl = "https://www.youtube.com/watch?v=6pIyg35wiB4";

        var client = new WebClient();
        var videoPageData = client.DownloadString(videoUrl);

        var encodedSignature = SignatureRegex.Match(videoPageData).Groups["Signature"].Value;

        var playerVersion = PlayerVersionRegex.Match(videoPageData).Groups["PlayerVersion"].Value;
        var playerScriptUrl = string.Format(PlayerScriptUrlTemplate, playerVersion);
        var playerScript = client.DownloadString(playerScriptUrl);

        var decodeFunctionName = DecodeFunctionNameRegex.Match(playerScript).Groups["FunctionName"].Value;
        var decodeFunction = Regex.Match(playerScript, DecodeFunctionPatternTemplate.Replace("#NAME#", decodeFunctionName)).Value;
        var helperObjectName = HelperObjectNameRegex.Match((decodeFunction)).Groups["ObjectName"].Value;
        var helperObject = Regex.Match(playerScript, HelperObjectPatternTemplate.Replace("#NAME#", helperObjectName)).Value;

        var engine = new ScriptEngine(ScriptEngine.JavaScriptLanguage);
        var decoderScript = engine.Parse(helperObject + decodeFunction);
        var decodedSignature = decoderScript.CallMethod(decodeFunctionName, encodedSignature).ToString();

        // Jint variant
        //var engine = new Engine();
        //var decoderScript = engine.Execute(helperObject).Execute(decodeFunction);
        //var decodedSignature = decoderScript.Invoke(decodeFunctionName, encodedSignature).ToString();

        Console.WriteLine("Encoded Signature\n{0}.\n{1}", encodedSignature.Split('.').First(), encodedSignature.Split('.').Last());
        Console.WriteLine();
        Console.WriteLine("Decoded Signature\n{0}.\n{1}", decodedSignature.Split('.').First(), decodedSignature.Split('.').Last());
        Console.ReadLine();
    }
开发者ID:Herrie82,项目名称:lune-tube,代码行数:32,代码来源:untitled.cs

示例2: GetEntityList

        /// <summary>
        /// 解析实体
        /// </summary>
        /// <param name="content">正文</param>
        /// <param name="company">查询的企业名称</param>
        /// <param name="taskGuid"></param>
        /// <param name="isAccurateSearch">是否精确搜索</param>
        /// <returns></returns>
        private List<QgOrgCodeEntity> GetEntityList(string content, string company, Guid taskGuid, bool isAccurateSearch = true)
        {
            List<QgOrgCodeEntity> cusList = new List<QgOrgCodeEntity>();
            if (!string.IsNullOrEmpty(content))
            {
                content = content.Replace("\n", " ") + ";function resultJson(){return JSON.stringify(s0[1]);}";
                object x = null;
                using (var engine = new ScriptEngine("jscript"))
                {
                    var parsed = engine.Parse(TaskList.GetKey() + content);
                    try
                    {
                        x = parsed.CallMethod("resultJson", null);
                    }
                    catch (Exception e)
                    {
                        new LogDomain().Add(new LogEntity { Details = Task.CurrentId + "线程错误:" + e.Message, ErrorDetails = e.ToString(), LogType = "error", TriggerTime = DateTime.Now });
                    }
                    if (x != null) cusList = JsonConvert.DeserializeObject<List<QgOrgCodeEntity>>(x.ToString());
                }
            }
            if (isAccurateSearch)
            {
                cusList = cusList.Where(m => m.jgmc.Equals(company)).ToList();
            }

            cusList.ForEach(m => { m.companyName = company; m.TaskGuid = taskGuid; m.InsertTime = DateTime.Now; });
            if (cusList.Count < 1)
            {
                cusList = new List<QgOrgCodeEntity> { new QgOrgCodeEntity { companyName = company, TaskGuid = taskGuid, InsertTime = DateTime.Now } };
            }
            return cusList;
        }
开发者ID:CBDlkl,项目名称:LiGather,代码行数:41,代码来源:QgCrawler.cs


注:本文中的ScriptEngine.Parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。