通过手机中的应用程序以编程方式按下网站中的按钮 [英] Programatically press a button in a website from an app in a phone

查看:18
本文介绍了通过手机中的应用程序以编程方式按下网站中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 c# 创建一个 UWP 应用程序.该应用程序应该从网站获取信息并将其呈现给用户.我已经浏览了该站点的 DOM 并设法下载了该站点的 HTML.但是有些信息是隐藏的,只有在网站上进行了某些按钮或选择时才会出现.有没有办法以编程方式进入网站,进行选择,下载新的 html?

第二个问题:应用程序应该有一个链接到一个 fb 页面的 fb liveChat 功能.我如何将 facebook liveChat 链接到这个应用程序?我不知道如何进行这项工作.谢谢你的帮助.

解决方案

这是在搜索框中输入文本并在 Bing 中单击搜索按钮的示例

  1. 使用 WebView 做所有的工作

    WebView webView = new WebView();

  2. 使用 InvokeScriptAsync 方法让WebView使用JS代码

    webView.InvokeScriptAsync("eval", new string[] {});

  3. 使用以下代码获取网站的 HTML

    public LoadURI(){webView.Navigate(new Uri("https://www.bing.com/"));webView.NavigationCompleted += webView_NavigationCompletedAsync;}字符串 siteHtML = null;私有异步无效 webView_NavigationCompletedAsync(WebView 发送者,WebViewNavigationCompletedEventArgs args){siteHtML = await webView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });}

  4. 使用以下代码在搜索框中输入文本

    private async void EnterTextAsync(string enterText){var functionString = string.Format(@"document.getElementsByClassName('b_searchbox')[0].innerText = '{0}';", enterText);await webView.InvokeScriptAsync("eval", new string[] { functionString });}

  5. 模拟点击使用以下代码

    private async void SimulateClickAsync(){var functionString = string.Format(@"ddocument.getElementsByClassName('b_searchboxSubmit')[0].click();");await webView.InvokeScriptAsync("eval", new string[] { functionString });}

  6. 使用步骤 3
  7. 获取新网站的 HTML

以下是登录 StackOverflow 的示例应用:StackOverFlow-LogIn

I am creating a UWP app using c#. The app is supposed to fetch information from a website and present it to the user. I've went through the DOM of the site and managed to download the HTML of the site. But some of the information is hidden and only appears when certain buttons or selections are made on the website. Is there a way that I can programmatically go into the site, make a selection, the download the new html?

2nd Question: The app should have an fb liveChat function linked an fb page. How do I link facebook liveChat into this app? I do not have an idea in my head on how to make this work. Thank you for you help.

解决方案

Here is an example for Entering text in search box and Click search button in Bing

  1. Use WebView to do all the work

    WebView webView = new WebView();
    

  2. Use InvokeScriptAsync method for WebView to use JS code

    webView.InvokeScriptAsync("eval", new string[] {});
    

  3. Get the HTML of the site using below code

    public LoadURI()
    {
        webView.Navigate(new Uri("https://www.bing.com/"));
        webView.NavigationCompleted += webView_NavigationCompletedAsync;
    }
    
    string siteHtML = null;
    
    private async void webView_NavigationCompletedAsync(WebView sender, WebViewNavigationCompletedEventArgs args)
    {
        siteHtML = await webView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });
    }
    

  4. Enter text in search box using below code

    private async void EnterTextAsync(string enterText)
    {
        var functionString = string.Format(@"document.getElementsByClassName('b_searchbox')[0].innerText = '{0}';", enterText);
        await webView.InvokeScriptAsync("eval", new string[] { functionString });
    }
    

  5. Simulate click using below code

    private async void SimulateClickAsync()
    {
        var functionString = string.Format(@"ddocument.getElementsByClassName('b_searchboxSubmit')[0].click();");
        await webView.InvokeScriptAsync("eval", new string[] { functionString });
    }
    

  6. Get new site's HTML using Step 3

Here is a Sample app for LogIn to StackOverflow: StackOverFlow-LogIn

这篇关于通过手机中的应用程序以编程方式按下网站中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆