How can I use Webview to load a web page in UWP - c#

// I want my Application to point to a particular page of a site and display it on webview, I tried this but not working
string site = "https://google.com";
myweb.Navigate(new Uri(site));

try the following:
string site = #"https://google.com";
myweb.Navigate(new Uri(site));
or
myweb.Navigate(new Uri(#"https://www.google.com"));

Related

Replicate Webbrowser Save Page As function in C#

I'm looking for a method that replicates a Web Browsers Save Page As function (Save as Type = Text Files) in C#.
Dilemma: I've attempted to use WebClient and HttpWebRequest to download all Text from a Web Page. Both methods only return the HTML of the web page which does not include dynamic content.
Sample code:
string url = #"https://www.canadapost.ca/cpotools/apps/track/personal/findByTrackNumber?trackingNumber=" + package.Item2 + "&LOCALE=en";
try
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;
using (WebClient client = new WebClient())
{
string content = client.DownloadString(url);
}
}
The above example returns the HTML without the tracking events from the page.
When I display the page in Firefox, right click on the page and select Save Page As and save as Text File all of the raw text is saved in the file. I would like to mimic this feature.
If you are scraping a web page that shows dynamic content then you basically have 2 options:
Use something to render the page first. The simplest in C# would be to have a WebBrowser control, and listen for the DocumentCompleted event. Note that there is some nuance to this when it fires for multiple documents on one page
Figure out what service the page is calling to get the extra data, and see if you can access that directly. It may well be the case that the Canadapost website is accessing an API that you can also call directly.

How to get url of navigated page 2 after button click of page 1 using WebBrowser Control in C#

I'm successfully navigating from www.url1.com to www.url2.com using webbrowser control but iam unable to get the url of navigated page i.e., www.url2.com, using Webbrowser control in asp.net web application.
Example:
I navigated to www.google.com
webBrowser.Navigate("http://www.google.com");
in that page i programatically given some text and click google search button as follow
HtmlElement textElement = webBrowser.Document.All.GetElementsByName("q")[0];
textElement.SetAttribute("value", "your text to search");
HtmlElement btnElement = webBrowser.Document.All.GetElementsByName("btnG")[0];
btnElement.InvokeMember("click");
After it navigated to
[https://www.google.co.in/?gfe_rd=cr&ei=dFMuWdWCHory8Afuwqog#q=your+text+to+search"]
Here my Question is How to get the that particular navigated url USING WEBBROWSER CONTROL IN c# i.e.,
**https://www.google.co.in/?gfe_rd=cr&ei=dFMuWdWCHory8Afuwqog#q=your+text+to+search"**
If you have any solution regarding this issue please share with me.
Thanks in advance.
You can access the Url via Navigated event:
https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.navigated(v=vs.110).aspx
Use href to link the page since it is a web application
Google

how to display full Url in web browser control properly in C#?

I can display the Url in the searchbar. However, it picks up javascript and other loading processes as URL and displays them and doesn't display a conventional Url (e.g https://stackoverflow.com/questions) that we would see in any common browser. So if I search http://www.stackoverflow.com, I get https://ssum-sec.casalemedia.com/usermatch?s=183712&cb=https://engine.adzerk.net/udb/22/sync/i.gif?partnerId=1&userId=. Any help would be appreciated.
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
player.SoundLocation = "safepage.wav";
player.Play();
if (SearchBar.Text != e.Url.ToString()) //Displays the full Webpage address within the textbox
{
SearchBar.Text = e.Url.ToString();
}
}
Navigation events of web browser control will raise for iframes of the page too. So in this case, what you are getting as result is address of an iframe in the page.
You can use webBrowser1.Url.ToString() instead of e.Url.ToString().
Note: As far as I know, there should not be an iframe in stackoverflow questions page, so itt seems your browser has been infected.
In the _Navigated event, you can use the WebBrowser.Url property. It will get updated each time but not for the redirects like for those tracking/ad scripts.

WPF C# CefSharp Navigate URL

I want to navigate new link like VS in webbrowser control but i can't this with wpf.
This for ie;
WebBrowser.Navigate("http://www.bing.com");
How is it done with CefSharp in WPF?
In cefsharp, you can do it like
string navigateUrl = "http://www.bing.com";
ChromiumBrowser.Address = navigateUrl; //navigates to the URL
//or use Reload method if you want to reload it
ChromiumBrowser.Reload(true);

Win8/Metro: Url and Document in WebView control?

I am creating a metro-style version for one of my apps, coded in c#. I need to access a web page, get the url and html code from that page and then use them.
In the winforms version, i used a WebBrowser control and its properties, .Url and .Document.ActiveElement.OuterHtml/InnerHtml.
For the metro-style app, i used a WebView control to access the page but it doesn't have such properties and i can't find anywhere how to get the url and the html code.
Anybody knows how to do that? Thanks in advance!
Edit: something like this (winforms, C#):
webBrowser1.DocumentCompleted+=delegate
{
if (webBrowser1.Url.ToString ().StartsWith ("http://www.google.com/"))
{
string url=webBrowser1.Url.ToString ();
string htmlCode=webBrowser1.Document.ActiveElement.InnerHtml;
}
};
I hope that this is the answer you need.

Categories

Resources