Problem with WebView

CzebokCzebok Member

Hi. I'm creating a mobile app of existing website. I use HTMLAGILITYPACK to scrap some data from website. I want to display them in my app. But there is no result and nothing displays.

This is my App code with "scraper":

namespace Apka
{
    public partial class App : Application
    {
        public static string DocumentPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        public static string strona = "";


        public static NavigationPage NavigationPage { get; private set; }
        WebRequest request = HttpWebRequest.Create("www.wiocha.pl");
        WebResponse response;

        public App()
        {


            InitializeComponent();

            starthttp();





            NavigationPage = new NavigationPage(new MainPage());
            RootPage rootPage = new RootPage();
            MenuPage menuPage = new MenuPage(rootPage.vm);

            rootPage.Master = menuPage;
            rootPage.Detail = NavigationPage;
            MainPage = rootPage;

        }


        private async void starthttp()
        {

            response = await Task.Factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null);

            var html = new HtmlDocument();
            html.Load(response.GetResponseStream());
            var nodes = html.DocumentNode.Descendants("img")
                .Where(node => node.GetAttributeValue("class", "")
                   .Equals("imageitself")).ToList();





            foreach (var node in nodes)
            {

                strona = strona + node.OuterHtml;

            }

            System.Diagnostics.Debug.WriteLine(strona);




        }
    }
}

In console it returns some img like blablabla

Here is my page where im trying to place scraped pictures:

namespace Apka.View.Pages
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MainPage : ContentPage
    {



        public MainPage()
        {
            InitializeComponent();

            WebView webView = new WebView
            {
                Source = new HtmlWebViewSource
                {
                    Html = @"<!DOCTYPE html><html><head><style>img { width:100%; }</style></head><body>" + App.strona + @"</body></html>",
                },
                VerticalOptions = LayoutOptions.FillAndExpand

            };



            /* ViewModel.Pages.MainPageViewModel vm = new ViewModel.Pages.MainPageViewModel();
             this.BindingContext = vm;*/
        }





    }
}

And XAML code to this page looks like that:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="" (cant place links)
             xmlns:x="" (here too)
             x:Class="Apka.View.Pages.MainPage">


    <ContentPage.ToolbarItems>
        <ToolbarItem Command="{Binding MenuItem1Command}" />
    </ContentPage.ToolbarItems>
    <ContentPage.Content>

        <StackLayout BackgroundColor="#505050" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">



        </StackLayout>

    </ContentPage.Content>
</ContentPage>

Why webview doesn't work? What should I do to display these pictures?

Answers

  • CzebokCzebok Member

    There should be html code for picture bracket img src-"link" class="imageitself" alt="blablabla" bracket

    instead of that

    In console it returns some img like blablabla

  • DobiDobi Member

    help him noobs

  • TiagoRodriguesNesTiagoRodriguesNes USMember ✭✭

    have you tried using HTTPClient ?

    var uri = new Uri("www.wiocha.pl");
    HttpClient client = new HttpClient();
    var response = await client.GetAsync(uri);
    if (response.IsSuccessStatusCode)
    {
        var content = await response.Content.ReadAsStringAsync();
        // ... deal with data received ...
     }
    
Sign In or Register to comment.