我需要一個C#中的MediaWiki解析器。
(http://www.mediawiki.org/wiki/Alternative_parsers)
既然沒有,我真的想要一個MediaWiki解析器而不是其他一些,比如WikiPlex,我正在研究使用另一種語言的一些現有解析器,並且能夠成功調用kiwi解析器爲了達成這個。但是,問題是它不能正確處理Unicode/UTF-8。現在KeyNotFoundException調用IronPython
,我想用這個腳本:
http://www.connellybarnes.com/code/python/mw2html
並通過IronPython的使用它。
我使用的IronPython 2.7從這裏開始:
http://ironpython.net/
我下載的二進制壓縮文件(不是安裝程序)。
然後我用這個教程作爲基礎:
http://www.codeproject.com/KB/cs/IronPythonMethod_CShap.aspx
這就是我所做的:
using System;
using IronPython.Hosting;
namespace IronPythonMethodInvokationDemo
{
class Program
{
// http://stackoverflow.com/questions/6557494/referencing-python-import-assemblies-when-calling-from-ironpython-in-c
static void Main(string[] args)
{
//Microsoft.Scripting.Hosting.ScriptEngine m_engine = Python.CreateEngine(DefaultEngineOptions());
Microsoft.Scripting.Hosting.ScriptEngine m_engine = Python.CreateEngine();
System.Collections.Generic.ICollection<string> paths = m_engine.GetSearchPaths();
paths.Add(@"D:\username\Documents\Visual Studio 2010\Projects\IronPython\IronPython-Bin-2.7\IronPython-2.7\Lib"); // modules path
paths.Add(@"D:\username\Documents\Visual Studio 2010\Projects\IronPython\IronPython-Bin-2.7\IronPython-2.7"); // ipy.exe path
m_engine.SetSearchPaths(paths);
//Step 1:
//Creating a new script runtime
//var ironPythonRuntime = Python.CreateRuntime();
var ironPythonRuntime = m_engine.Runtime;
try
{
//Step 2:
//Load the Iron Python file/script into the memory
//Should be resolve at runtime
//dynamic loadIPython = ironPythonRuntime.UseFile("first.py");
//ironPythonRuntime.GetBuiltinModule();
dynamic loadIPython = ironPythonRuntime.UseFile("mw3html.py");
//Step 3:
//Invoke the method and print the result
/*
Console.WriteLine(
string.Format("Addition result from IronPython method for {0} and {1} is {2}",
100,200, loadIPython.add(100, 200))
);
*/
Console.WriteLine(string.Format("Result for IronPython main method: {0}", loadIPython.main()) );
} // End Try
catch (System.IO.FileNotFoundException ex)
{
Console.WriteLine(ex.Message);
} // End Catch
Console.ReadKey(true);
} // End Sub Main
} // End Class Program
} // End Namespace IronPythonMethodInvokationDemo
如果我使用first.py,然後一切工作正常。 現在,使用mw2html.py,我得到ironPythonRuntime.UseFile( 「mw3html.py」)一
KeyNotFoundException;對於 鍵「」...
任何人都知道這意味着什麼?
這似乎是由導入urllib和導入urllib2引起的...它看起來像socket.py和其他一些不在lib文件夾中... –