[英]How can I load an HTML string into Webkit.net so I can access its “DOM”
[英]How can I access the DOM using WebKit.NET?
我在C#應用程序中使用WebKit來呈現CSS樣式的XML文檔,我希望能夠添加DOM元素。 如何訪問DOM才能執行此操作? 問題似乎是WebKitBrowser類中沒有屬性可以訪問私有webView成員。 可能嗎? 我是否需要修改類才能添加此項? 我只是做錯嗎?
從0.3.0開始,WebKit.Net似乎無法訪問encodeom。 我做了一些稍微不同的事情,我使用了WebKit.Net,但我在應用程序中添加了一個HTTP偵聽器,並設置了控件以從那里檢索頁面。 通過這種方式,我可以訪問同一個應用程序中的帖子和回調。 其余的我自己在頁面上使用JavaScript。
HttpListener listener;
public Form1( ) {
InitializeComponent( );
listener = new System.Net.HttpListener( );
listener.Prefixes.Add( "http://*:88/" );
listener.Start( );
IAsyncResult result = listener.BeginGetContext( new AsyncCallback( ListenerCallback ), listener );
}
public static void ListenerCallback( IAsyncResult result ) {
string resp = "<body>test</body";
HttpListener listener = ( HttpListener )result.AsyncState;
// Call EndGetContext to complete the asynchronous operation.
try {
HttpListenerContext context = listener.EndGetContext( result );
HttpListenerRequest request = context.Request;
// Obtain a response object.
HttpListenerResponse response = context.Response;
// Construct a response.
string webpage = request.Url.AbsolutePath.Substring( 1 );
string responseString = null;
if ( string.IsNullOrEmpty( webpage ) ) {
responseString = resp;
}
else {
webpage = webpage.Replace( ".", "_" );
responseString = webkit_test.Properties.Resources.ResourceManager.GetResourceSet( System.Globalization.CultureInfo.CurrentCulture, true, false ).GetObject( webpage ) as string;
if ( responseString == null ) {
responseString = "<html></html><body> 404 Web Page not Found</body>";
}
}
byte[ ] buffer = System.Text.Encoding.UTF8.GetBytes( responseString );
// Get a response stream and write the response to it.
response.ContentType = "text/html; charset=UTF-8";
response.ContentLength64 = buffer.Length;
System.IO.Stream output = response.OutputStream;
output.Write( buffer, 0, buffer.Length );
output.Flush( );
// You must close the output stream.
output.Close( );
IAsyncResult result1 = listener.BeginGetContext( new AsyncCallback( ListenerCallback ), listener );
}
catch { }
}
順便說一句。 該代碼還將從嵌入資源中讀取網頁
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.