Simple C# Webscraping using Scrapysharp test not working

1.4k Views Asked by At

I never did any webscraping before and just started out. The NavigateToPage function never finishes however.

This is my code:

ScrapingBrowser Browser = new ScrapingBrowser();
Browser.AllowAutoRedirect = true;
Browser.AllowMetaRedirect = true;
WebPage PageResult = Browser.NavigateToPage(new Uri("URI"));
HtmlNode TitleNode = PageResult.Html.CssSelect(".navbar-brand").First();
string PageTitle = TitleNode.InnerText;

It keeps on loading when navigating to any website (and it does not work in localhost either), but it does not timeout. As far as I know the code is correct. So I was wondering what else could be a problem here?

1

There are 1 best solutions below

0
geoapps On

Try not to invoke navigation in the main UI thread:

await Task.Factory.StartNew( ()=> PageResult = Browser.NavigateToPage(new Uri("http://www.google.es")));