Using VB.NET and WinForms to get the HTML code of a visited site?

233 views
Skip to first unread message

Julian Schlüter

unread,
Nov 1, 2014, 7:55:05 AM11/1/14
to cefs...@googlegroups.com
Hello you guys!

I want to visit a website, toggle a login via jscript and then grab the whole html code of the page.

My first tries where using the WebBrowser control (IE) of VB.Net. 


            Dim oStream As Stream
            Dim oStreamReader As StreamReader

            Dim hReq As HttpWebRequest
            Dim hRes As HttpWebResponse

            hReq = DirectCast(HttpWebRequest.Create(sURL), HttpWebRequest)
            hRes = DirectCast(hReq.GetResponse(), HttpWebResponse)
            oStream = hRes.GetResponseStream()
            oStreamReader = New StreamReader(oStream)

            sSessionPage = oStreamReader.ReadToEnd()

            oStreamReader.Close()
            oStream.Close()
            oStreamReader = Nothing
            oStream = Nothing
            hReq = Nothing
            hRes = Nothing


I got the HTML. But I couldnt log in, as  i just couldnt get the jscripts invoked. 


Then I switched to the GeckoFX control (FireFox).
I could login and display the HTML in my control. But I couldnt grab the HTML and save it to a variable or a file.


Now I want to try this with the CefSharp control.

But I dont even know how to start.

I used the NuGet Package Manager to install the newest stable version.

But now Im stuck creating a control.. 


How do I create a browser control in CefSharp, how do I open a website at a given URL, invoke jscripts and how can I save the HTML code of the open site?


Hopefully you can help me with this task.


Greetings
Julian

Jørn Hansen

unread,
Nov 3, 2014, 2:15:39 AM11/3/14
to cefs...@googlegroups.com
On Saturday, November 1, 2014 12:55:05 PM UTC+1, Julian Schlüter wrote:
> Hello you guys!
>
>
> I want to visit a website, toggle a login via jscript and then grab the whole html code of the page.
>
Snip

>
>
>
>             Dim oStream As Stream
>             Dim oStreamReader As StreamReader
>
>
>             Dim hReq As HttpWebRequest
>             Dim hRes As HttpWebResponse
>
>
>             hReq = DirectCast(HttpWebRequest.Create(sURL), HttpWebRequest)
>             hRes = DirectCast(hReq.GetResponse(), HttpWebResponse)
>             oStream = hRes.GetResponseStream()
>             oStreamReader = New StreamReader(oStream)
>
>. 
>
>
>
>
> Then I switched to the GeckoFX control (FireFox).
> I could login and display the HTML in my control. But I couldnt grab the HTML and save it to a variable or a file.
>
>
>
>
> Now I want to try this with the CefSharp control.
>
>
> But I dont even know how to start.
>
>
> I used the NuGet Package Manager to install the newest stable version.
>
>
> But now Im stuck creating a control.. 
>
>
>
>
> How do I create a browser control in CefSharp, how do I open a website at a given URL, invoke jscripts and how can I save the HTML code of the open site?
>
For the first two questions see http://stackoverflow.com/a/26313817/210723

Calling JavaScript should be covered by the FAQ and/or the CefSharp.Wpf.Example - run it and you will see :-)

For copying the HTML see https://github.com/cefsharp/CefSharp/blob/v33.0.2/CefSharp.WinForms.Example/BrowserTabUserControl.cs#L159

--
Best regards,
JornH
Reply all
Reply to author
Forward
0 new messages