Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting web page text from a WebBrowser window

Status
Not open for further replies.

5ilver5aracen

Programmer
Oct 24, 2004
32
GB
Hi, I've just written a VB6 project that uses WebBrowser to access a web page. I now need to pull data from this web page. I have tried:

myVar = Browser.Document.body.innerText

That works ok to a point. If there are table cells on the web page the data is returned all bunched together unlike manually selecting all and copying all. How do I select all the text in the browser window and place it into a var?

Many thanks in advance
 
I know this may sound silly, but why not use the Inet control to query the website after you have viewed the webpage?

MyVar = Inet1.navigate ("
The inet control gathers all of the available text from the site as if you clicked "view Source" in the Internet Explorer browser.

Hope this helps...

LF
 
Thanks for that. I dont need to grab the source text though. I'm just after simulating Ctr 'A' and Ctr 'C', selecting the text on the page and copying it into a var.
Can that be done with either WebBrowser or Inet?
 
Well, you see, when Inet retrieves the source text, you can then parse it to gather whatever text you need and have that stored inside of a variable. Here is a bit of code that will parse out the text between two strings for you. So if you know the text(source) directly preceding the text you wish to put inside of a variable, and you know the text that is directly after the text you wish to get, then this will return that text...

Function Gettext(strText, strStarttag, strEndTag)

Dim intStart

intStart = InStr(1, strText, strStarttag, vbTextCompare)
If intStart Then
intStart = intStart + Len(strStarttag)
intend = InStr(intStart + 1, strText, strEndTag, vbTextCompare)
Gettext = Mid(strText, intStart + 1, intend - intStart - 1)

Else
Gettext = " "

End If



End Function

Put this code in a module, and call it by this method

MyText = GetText(strTEXT, strStartTag, strEndTag)

Where strTEXT = the web page source text

strStartTag = the text directly preceding the text you wish to grab

strEndTag = the text directly after the text you wish to grab.

Let me know if you need further help with this...

LF



"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Neat function. Thanks for that. I have already written a program that parses the text. For what I want its a much simpler, easier process than parsing the html. The 'copied' text comes with vbcrlf's all in the right places. Is it possible than I can simulate a keyboard Ctrl 'A' & Ctrl 'C' on the WebBrowser?
 
hmm. I am not really sure to be honest... I mean, one could use a sequence of the SendKeys function to do the actual CTRL + A & CTRL + C , but you would have to see if you could TAB to the section, in your browser, which you wish to copy and then do a SendKeys Home + End type deal. There is a SendKeys VbTabkey. This sounds much more complicating than simply parsing the HTML. I am not really sure how to go about this.

LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top