简体   繁体   English

Xamarin Forms 将 WebView 内容作为字符串获取

[英]Xamarin Forms get WebView content as string

Is it possible to get the content of a WebView as a string?是否可以将 WebView 的内容作为字符串获取?

I tried using:我尝试使用:

HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Constants.LOGIN_URL);

HttpWebResponse response = (HttpWebResponse)await httpWebRequest.GetResponseAsync();

But I didn't get what i wanted because the webview stores the sessions etc.但是我没有得到我想要的东西,因为 webview 存储了会话等。

I want a method to get the data of a logged in user from a website if this is possible.如果可能的话,我想要一种从网站获取登录用户数据的方法。

Since you need to download the content of the WebView in the context of a logged in user, you may want to try injecting JavaScript into the WebView and then having the JavaScript send code back to a C# method.由于您需要在登录用户的上下文中下载WebView的内容,您可能想要尝试将JavaScript注入WebView ,然后让JavaScript将代码发送回C#方法。

An example of something like this can be found in XLabs' Hybrid WebView (which is the example I used to call JavaScript from C# methods).可以在 XLabs 的Hybrid WebView找到类似的示例(这是我用来从C#方法调用JavaScript的示例)。

Have a look at the URL below.看看下面的网址。 You will need to create a custom renderer for each platform that you support but that should just be a matter of copying and pasting from the link below.您需要为您支持的每个平台创建一个自定义渲染器,但这应该只是从下面的链接复制和粘贴的问题。

Once you have you custom renderer all set, you can simply pull all of the HTML using a JavaScript method.设置好自定义渲染器后,您可以使用JavaScript方法简单地提取所有HTML

https://github.com/XLabs/Xamarin-Forms-Labs/wiki/HybridWebView https://github.com/XLabs/Xamarin-Forms-Labs/wiki/HybridWebView

Reply back if you run into any road blocks.如果遇到任何障碍,请回复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM