2

I am currently doing some web scraping on a website, however the website required the javascript so i need to use the browser function to wait them like 10 seconds to loaded all the javascript. However, if i load the page it will prompt me the message box upon the navigation enter image description here

however, from what i investigate online like the online article , it asked me to use this function

webBrowser1.ScriptErrorsSuppressed = true;

but it does not work and the message still continue, the following is my code, may i ask how to get rid of that message box?

protected void Page_Load(object sender, EventArgs e)
    {
        var t = new Thread(sdsadas);
        t.SetApartmentState(ApartmentState.STA);
        t.Start();
    }

    private void sdsadas()
    {
        WebBrowser wb = new WebBrowser();
        wb.DocumentCompleted += Wb_DocumentCompleted;

        wb.ScriptErrorsSuppressed = true;
        wb.Navigate("a123");
        System.Windows.Forms.Application.Run();

    }

    private void Wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        var wb = (WebBrowser)sender;
        string content = wb.Document.Body.InnerHtml;
        while (wb.ReadyState != WebBrowserReadyState.Complete)
        {
            System.Windows.Forms.Application.DoEvents();
        }
        var html = wb.Document.GetElementsByTagName("HTML")[0].OuterHtml;
        /* ... */
    }
Ryan Shine
  • 442
  • 1
  • 9
  • 23

0 Answers0