Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to select a piece of text in TWebbrowser?

Posted on 2004-10-17
5
Medium Priority
?
193 Views
Last Modified: 2010-04-05
For example, I've got a dynamic web page. For instance, this is a part of the content of the web page:

...
August 24, 2004
Today's Quote of the Day: 'The first string between the quotation mark'
...

the day after that, the part is:

...
August 25, 2004
Today's Quote of the Day: 'The second string between the quotation mark'
...

What I want to do is getting only the string between the quotation mark. How can I do that?
0
Comment
Question by:cctest
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 

Accepted Solution

by:
Jana618 earned 500 total points
ID: 12336283
Most reliably, looking at the source of the page, if the item you want always appears at a given tab index or field name you can retrieve the text using a TWebBrowser by:

(I think it needs mshtml in the uses clause, maybe other?)
var
  i, j: Integer;
  FormItem: Variant;
begin
  try
    //no form on document
    if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
      Exit;
    //count forms on document
    for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
    begin
      FormItem := WebBrowser.OleObject.Document.forms.Item(I);
      for j := 0 to FormItem.Length - 1 do
      begin
          try

            //BY TAB INDEX
            if j = TabIndex then begin
              OutputRichEdit.Lines.Text := FormItem.Item(j).Value;
              Exit;
            end;
          except
            Exit;
          end;

          //OR BY FIELD NAME
            if WideSameText(FormItem.Item(j).Name, FieldName) then begin
              OutputRichEdit.Lines.Text := FormItem.Item(j).Value;
              Result := True;
              Exit;
            end;
          except
            Exit;
          end;

        end;

Otherwise you could try HTML page scraping:
http://delphi.about.com/library/weekly/aa062502a.htm 

Or, if the text on the page around the quote you want is static, you could retrieve only the displayed text from the page (for my example if you can cast as an IHTMLDocument2) and locate the unkown text you want via the same kind of stripping of the known text (ie Today's Quote of the Day: ') from either side...

(again, I think it needs mshtml in the uses clause, maybe other?)
  var
    txtRnge: IHTMLTxtRange; //TextRange Object
  begin
      try
        txtRnge := ((MyWebBrowser.Document as IHTMLDocument2).body
          as IHTMLBodyElement).createTextRange;
        OutputRichEdit.Lines.Text := txtRnge.Get_text;
      except
          Exit;
      end;

Good luck...
Jana
0
 

Expert Comment

by:Jana618
ID: 13359454
there are three viable methods here...
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question