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

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

问题描述

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

第二个问题:该应用应具有链接到fb页面的fb liveChat函数.如何将facebook liveChat链接到此应用程序?我对如何进行这项工作一无所知.谢谢您的帮助.

解决方案

以下是在搜索框中输入文字并在必应中单击搜索按钮的示例

  1. 使用 WebView 完成所有工作

    WebView webView = new WebView();
    

  2. 使用

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

    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. 使用以下代码在搜索框中
  5. 输入文本

    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 });
    }
    

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

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

  7. 使用第3步
  8. 获取新网站的HTML

以下是用于登录到StackOverflow的示例应用程序: StackOverFlow-登录

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天全站免登陆