Getting text from webpage

Having problems with building or using the CefSharp .NET binding? Ask your CEF-related questions here. Please ask general usage questions on StackOverflow.

Moderator: amaitland

Getting text from webpage

Postby catflap999 » Sat Jan 15, 2022 8:38 am

Hi

I just started using cefsharp and it's looking good so far, but I'm a bit stuck now, so need some help.

I've created a form in vb.net with a chromium web browser on it. I've got the code sorted to navigate to a website OK, wait for the page to finish loading, and then press a button.

What I now need to do is copy the text on tha page to a string variable so I can do some searching for certain keywords.

How do I get access to the text currently displayed on the web browser please?

Thanks for reading!
catflap999
Newbie
 
Posts: 4
Joined: Sat Jan 15, 2022 8:30 am

Re: Getting text from webpage

Postby amaitland » Sat Jan 15, 2022 2:40 pm

Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: Getting text from webpage

Postby catflap999 » Mon Jan 17, 2022 4:01 am

Thanks for reply. I tried:

Dim mytext = browser1.GetTextAsync

but this just gives me:

Code: Select all
Id = 4, Status = WaitingForActivation {1}, Method = "{null}", Result = "{Not yet computed}"
AsyncState: Nothing
CancellationPending: False
CreationOptions: None {0}
Exception: Nothing
Id: 4
Result: Nothing
Status: WaitingForActivation {1}


So presumably I need to 'activate' the control first? - how do I do that?

EDIT: by the way, I am waiting for browser.IsLoading = False before trying to get the text, if that's relevant?
catflap999
Newbie
 
Posts: 4
Joined: Sat Jan 15, 2022 8:30 am

Re: Getting text from webpage

Postby amaitland » Mon Jan 17, 2022 4:27 am

The method returns a Task, you should await the task to get the result.

https://docs.microsoft.com/en-us/dotnet ... pts/async/

Nothing to do with activating the control.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: Getting text from webpage

Postby catflap999 » Mon Jan 17, 2022 5:41 am

Hi

I'm afraid I'm not familiar with this? - any chance you could provide some sample code please?
catflap999
Newbie
 
Posts: 4
Joined: Sat Jan 15, 2022 8:30 am

Re: Getting text from webpage

Postby amaitland » Mon Jan 17, 2022 2:38 pm

It's a standard language feature, plenty of resources online covering the topic. Vb.net is not something I can help you with.

Quick search brings up https://stackoverflow.com/a/41065216/4583726

Past that you'll have to do your own research.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: Getting text from webpage

Postby catflap999 » Tue Jan 18, 2022 3:47 am

Thanks for the pointer - I'll look into it.
catflap999
Newbie
 
Posts: 4
Joined: Sat Jan 15, 2022 8:30 am


Return to CefSharp Forum

Who is online

Users browsing this forum: No registered users and 1 guest