簡體   English   中英

通過電話中的應用程序以編程方式按下網站中的按鈕

[英]Programatically press a button in a website from an app in a phone

我正在使用C#創建UWP應用。 該應用程序應該從網站上獲取信息並將其呈現給用戶。 我瀏覽了該站點的DOM並設法下載了該站點的HTML。 但是某些信息是隱藏的,僅在網站上進行某些按鈕或選擇時才會顯示。 有沒有一種方法可以使我以編程方式進入站點,進行選擇,然后下載新的html?

第二個問題:該應用程序應具有鏈接fb頁面的fb liveChat函數。 如何將facebook liveChat鏈接到此應用程序? 我不知道如何進行這項工作。 謝謝你的幫助。

這是在搜索框中輸入文本並在Bing中單擊搜索按鈕的示例

  1. 使用WebView來完成所有工作

     WebView webView = new WebView(); 
  2. 對WebView使用InvokeScriptAsync方法以使用JS代碼

     webView.InvokeScriptAsync("eval", new string[] {}); 
  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. 使用以下代碼在搜索框中輸入文本

     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步獲取新網站的HTML

這是用於登錄到StackOverflow的示例應用程序: StackOverFlow-LogIn

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM