TWebBrowser and facebook.com

If you have a programming question, please feel free to post it here. Non-programming questions will be moved to Miscellaneous or deleted.

TWebBrowser and facebook.com

by mathgod » 19/10/09 20:00

I recently coded a few demos using the TWebBrowser component. My facebook feed loads nicely but I am too inexperienced with TWebbrowser to do what I want. The content of the facebook feed is not static HTML but is dynamically created with Ajax (I think). This is what I want to do: 1 ) load my facebook feed into the Webbrowser every 30 seconds. 2 ) check new links (if any) for the string "sheep_black" occurring in the href value of the anchor tag as opposed to the displayed text. 3 ) click the link that contains "sheep_black". 4 ) (optional) do not click a link more than once. Please help.
mathgod
Active Member
Active Member
 
Posts: 23
Joined: 15/12/07 16:36
Location: Middle of New Mexico, USA

Re: TWebBrowser and facebook.com

by Kambiz » 19/10/09 22:25

Are you going to automatically adopt the found animals in FarmVille?
Kambiz

Donate a cup of food for free: Click to Give @ The Hunger Site

Kambiz
Administrator
Administrator
 
Posts: 1868
Joined: 07/03/03 19:10
Location: Tehran, Iran

Re: TWebBrowser and facebook.com

by mathgod » 19/10/09 23:52

The adoption is still random. A black sheep harvester will not guarantee an adoption. I just don't want to miss anymore opportunities at adopting black sheep. Since the introduction of the pink cows, I have seen too many pink cows and very few black sheep. It seems as though that the black sheep show up at night or in the early morning.

Incidentally, I was using an exploit that has since been fixed to convert adoptable cows into black sheep. I would change cow_pink or cow_brown to sheep_black and I would get a black sheep. I mentioned this little trick on the FarmVille Forum and got banned. :-^ I wrote a Delphi application would make the change for me. I even included a panic button that would force the page to load in the event of an error page or the page not loading at all. The trick for that is to change the URL from "apps.facebook.com" to "apps.new.facebook.com".
mathgod
Active Member
Active Member
 
Posts: 23
Joined: 15/12/07 16:36
Location: Middle of New Mexico, USA

Re: TWebBrowser and facebook.com

by Kambiz » 20/10/09 10:35

First of all, instead of TWebBrowser use TEmbeddedWB <http://www.bsalsa.com/support.html>.

Use SaveToStrings method of TEmbeddedWB to save the source code of page in to a TStrings. After that, you can look for the adopt link in the strings.

Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
  // opens the feeds of FarmVille only
  EmbeddedWb1.Go('http://www.facebook.com/home.php?filter=app_102452128776');
  // saves the feeds in to a memo
  EmbeddedWb1.SaveToStrings(Memo1.Lines);
  // adopts the black sheep if any found
  AdoptBlackSheep(Memo1.Lines.Text);
end;
Kambiz

Donate a cup of food for free: Click to Give @ The Hunger Site

Kambiz
Administrator
Administrator
 
Posts: 1868
Joined: 07/03/03 19:10
Location: Tehran, Iran

Re: TWebBrowser and facebook.com

by mathgod » 21/10/09 02:48

Thank you, Kambiz. Would you like to have the application? I tested it and it works. :mrgreen:
mathgod
Active Member
Active Member
 
Posts: 23
Joined: 15/12/07 16:36
Location: Middle of New Mexico, USA

Re: TWebBrowser and facebook.com

by Kambiz » 22/10/09 07:37

Thank you! I have no more free space on my farm to place new animals/trees.

But I may be able to modify your app to use it for getting special achievement bonuses in Mafia Wars. :)
Kambiz

Donate a cup of food for free: Click to Give @ The Hunger Site

Kambiz
Administrator
Administrator
 
Posts: 1868
Joined: 07/03/03 19:10
Location: Tehran, Iran

Re: TWebBrowser and facebook.com

by mathgod » 22/10/09 22:34

There is only one unit for the project. I wrote this using Delphi Turbo Express (Delphi 2006 syntax).
Code: Select all
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, SHDocVw_EWB, EwbCore, EmbeddedWB, IEParser,
  ExtCtrls;

type
  TForm1 = class(TForm)
    EmbeddedWB1: TEmbeddedWB;
    Memo1: TMemo;
    Button1: TButton;
    GroupBox1: TGroupBox;
    CheckBoxPinkCow: TCheckBox;
    CheckBoxBrownCow: TCheckBox;
    CheckBoxBlackSheep: TCheckBox;
    CheckBoxUglyDuck: TCheckBox;
    IEParser1: TIEParser;
    Timer1: TTimer;
    Button2: TButton;
    ButtonStop: TButton;
    ButtonReload: TButton;
    Bevel1: TBevel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure IEParser1Anchor(Sender: TObject; hRef, Target, Rel, Rev, Urn,
      Methods, Name, Host, HostName, PathName, Port, Protocol, Search, Hash,
      AccessKey, ProtocolLong, MimeType, NameProp: string;
      Element: TElementInfo);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure ButtonStopClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ButtonReloadClick(Sender: TObject);
  private
    { Private declarations }
    function Visited(beta_url: String): Boolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses ShellAPI;
{$R *.dfm}
var
  Visited_links: Array[0..55] of String;
  Link_Cnt: Integer;

function TForm1.Visited(beta_url: string): Boolean;
var
  i: Integer;
  flag_bool: Boolean;
begin
  flag_bool:= False; i:= 0;
  while (not flag_bool) and (i < 56) do
    begin
       if Visited_links[i] = 'alpha' then i:= 55;
      if  beta_url = Visited_links[i] then flag_bool:= True;
      inc(i);
    end;
  Result:= flag_bool;
end;

// *********************************************************************
// *
// * FarmVille publishes two different anchors for the same object.
// *
// * Each time an animal or reward is found, two calls to ShellExecute
// * will be done. This is because there is an anchor for the image and
// * an anchor for the text.
// *
// *********************************************************************
procedure TForm1.IEParser1Anchor(Sender: TObject; hRef, Target, Rel, Rev, Urn,
  Methods, Name, Host, HostName, PathName, Port, Protocol, Search, Hash,
  AccessKey, ProtocolLong, MimeType, NameProp: string; Element: TElementInfo);
begin
    if (CheckBoxPinkCow.Checked = True) and (Pos('cow_pink', hRef) > 0) then
      begin
        Memo1.Lines.Add(#13#10 + 'link for pink cow : ');
        Memo1.Lines.Add(#13#10 + 'hRef: ' + hRef);
        if not Visited(hRef) then
          begin
          { open a web page }
  ShellExecute(Handle, 'open', Pchar(hRef), nil, nil, SW_SHOWNORMAL);
  Visited_links[Link_Cnt]:= hRef; inc(Link_Cnt);
  if Link_Cnt > 55 then Link_Cnt:= 0;
          end;
      end;  // if pink cow

    if (CheckBoxBrownCow.Checked = True) and (Pos('cow_brown', hRef) > 0) then
      begin
        Memo1.Lines.Add(#13#10 + 'link for brown cow : ');
        Memo1.Lines.Add(#13#10 + 'hRef: ' + hRef);
        if not Visited(hRef) then
          begin
          { open a web page }
  ShellExecute(Handle, 'open', Pchar(hRef), nil, nil, SW_SHOWNORMAL);
  Visited_links[Link_Cnt]:= hRef; inc(Link_Cnt);
  if Link_Cnt > 55 then Link_Cnt:= 0;
          end;
      end;  // if brown cow

    if (CheckBoxBlackSheep.Checked = True) and (Pos('sheep_black', hRef) > 0) then
      begin
        Memo1.Lines.Add(#13#10 + 'link for black sheep : ');
        Memo1.Lines.Add(#13#10 + 'hRef: ' + hRef);
        if not Visited(hRef) then
          begin
          { open a web page }
  ShellExecute(Handle, 'open', Pchar(hRef), nil, nil, SW_SHOWNORMAL);
  Visited_links[Link_Cnt]:= hRef; inc(Link_Cnt);
  if Link_Cnt > 55 then Link_Cnt:= 0;
          end;
      end;  // if black sheep

    if (CheckBoxUglyDuck.Checked = True) and (Pos('uglyduck', hRef) > 0) then
      begin
        Memo1.Lines.Add(#13#10 + 'link for ugly duckling : ');
        Memo1.Lines.Add(#13#10 + 'hRef: ' + hRef);
        if not Visited(hRef) then
          begin
          { open a web page }
  ShellExecute(Handle, 'open', Pchar(hRef), nil, nil, SW_SHOWNORMAL);
  Visited_links[Link_Cnt]:= hRef; inc(Link_Cnt);
  if Link_Cnt > 55 then Link_Cnt:= 0;
          end;
      end;  // if ugly duckling
    
// ********************* get coins ***********************************
    if Pos('reward', hRef) > 0 then
        if not Visited(hRef) then
          begin
          { open a web page }
  Memo1.Lines.Add(#13#10 + '$$$ coinage $$$');
  ShellExecute(Handle, 'open', Pchar(hRef), nil, nil, SW_SHOWNORMAL);
  Visited_links[Link_Cnt]:= hRef; inc(Link_Cnt);

  if Link_Cnt > 55 then Link_Cnt:= 0;
          end;          
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
IEParser1.Parse('http://www.facebook.com/home.php?filter=app_102452128776');
Application.ProcessMessages;
Memo1.Lines.Add('--- 50-second interval started ---');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Enabled:= False; ButtonStop.Enabled:= True;
// IEParser1.Parse('http://www.facebook.com/home.php?filter=app_102452128776');
Timer1.Enabled:= True;
Memo1.Lines.Add('Timer started.' + #13#10);
// adopts the black sheep if any found
// AdoptBlackSheep(Memo1.Lines.Text);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Memo1.Clear;
end;

procedure TForm1.ButtonReloadClick(Sender: TObject);
begin
// opens the feed of FarmVille only
EmbeddedWb1.Go('http://www.facebook.com/home.php?filter=app_102452128776');
end;

procedure TForm1.ButtonStopClick(Sender: TObject);
begin
  IEParser1.Stop;
  Timer1.Enabled:= False; Button1.Enabled:= True; ButtonStop.Enabled:= False;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  EmbeddedWb1.Free; IEParser1.Free;
  Timer1.Destroy;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
Link_Cnt:= 0;
// initialize string array
for  i := 0 to 25 do Visited_links[i]:= 'alpha';

// opens the feeds of FarmVille only
EmbeddedWb1.Go('http://www.facebook.com/home.php?filter=app_102452128776');
end;

end.
Here is a page with screen shot and download link for executable.
http://www.angelfire.com/ar/mathgod/farmville_orion.html
mathgod
Active Member
Active Member
 
Posts: 23
Joined: 15/12/07 16:36
Location: Middle of New Mexico, USA

Re: TWebBrowser and facebook.com

by Kambiz » 22/10/09 23:17

Thank you very much for the source and the credit.
By the way, my wife started using Orion. :)
Kambiz

Donate a cup of food for free: Click to Give @ The Hunger Site

Kambiz
Administrator
Administrator
 
Posts: 1868
Joined: 07/03/03 19:10
Location: Tehran, Iran


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 0 guests