Search code examples
c#webbrowser-controlcefsharp

extract links from web page on cefsharp


I'm working on an application to extract URLs from a web page, I'm using WebBrowser control we all know how bad is I wanna move to use cefsharp but I don't know much about it. this my code so far for extracting URLs that have "Http://" on it

web_search.Navigate("example.com");
private void web_search_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        var search_results = this.web_search.Document.Links.Cast<HtmlElement>().Select(a => a.GetAttribute("href")).Where(h => h.Contains("http://")).ToArray();

my point is when a page loaded well have a bunch of links to it so I'm trying to find a way to extract the hrefs values from those links


Solution

  • Most of times in CEF to manipulate with document is easier to use JS. Consider CEF wiki (and CefSharp samples) to learn how to execute JS and get result back. After that it will be trivial.