Jump to content

Read object value with FF.au3


Recommended Posts

Hi.

Someone know how to read an object's value (e.g. table cell from a webpage), using FF.au3 UDF, or any else? I mean,

$s = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[1]")

returns "OBJECT|FFau3.xpath", and not the value of that object, wich is text.. How could I obtain it?

Any suggestion is welcome. Thanks.

Andrew.

Edit:

Forgot to mention, the table (so cell) content is dinamically changing, so the info isn't static.

Edit2:

This post shows an eventually response, and I'v tried houndreds of variants, none worked.. Also, this one shows how to use it for what I need, but I couldn't figure out how to transform it to fit my needs..

Edited by andrew222

Everybody starts from somewhere..

Link to comment
Share on other sites

Maybe I wasn't that clear as some would expect, so let me rephrase the question..

How to convert an object (it's value) to a string? Possibly using _FFXPath()..

Once again, thank you..

Andrew.

Everybody starts from somewhere..

Link to comment
Share on other sites

Maybe I wasn't that clear as some would expect, so let me rephrase the question..

How to convert an object (it's value) to a string? Possibly using _FFXPath()..

Once again, thank you..

Andrew.

You must tell _FFXpath which information of this object you wanna read- e.g:

$s = _FFXPath("//table[@id='AutoNumber1']//tr[2]/td[1]", "textContent", 9)

or

$oTD = _FFXPath("//table[@id='AutoNumber1']//tr[2]/td[1]")
$s = _FFObj($oTD, "textContent")
Link to comment
Share on other sites

Hi Stilgar, and thank you for the answer..

I've tried both of your examples, but both returned an empty thing..

I give you the example page, so you can see it yourself..

#Include <FF.au3>
_FFStart("http://www.afacerilemn.ro/rom/files/detaliu_firma.php?n=ALEXTE-COM-SRL&id=19731")
;$oTD = _FFXPath("//table[@id='AutoNumber1']//tr[2]/td[1]") 
;$s = _FFObj($oTD, "textContent")
$s = _FFXPath("//table[@id='AutoNumber1']//tr[2]/td[1]", "textContent", 9)
msgbox(0,"",$s)
_FFQuit()

The name in the left, and the info on the right I need.. The example path is the name in the left.

Thank you very very much for the help.

Andrew.

Everybody starts from somewhere..

Link to comment
Share on other sites

Hello once again..

I figured out finaly, but it doesn't make any sense.. Instead of the short way, like you suggested, I tried the long way, like this:

$s = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[1]/b/font", "textContent", 9)

and it worked.. I have to tell, that even if someone doesn't believe me, this way I already tried before, several times, and never gaved me the result I wanted, so the only explanation to all this, in my opinion, can lead back to FireFox, wich in the last 3 days was updated 2 times..

Anyway, now it works the above code, with others as well, so my problem is solved..

Thank you Stilgar, and everybody..

Bless you,

Andrew.

Edit:

VERY IMPORTANT!!! I figured out another problem, wich could be, or could be not a bug. If I keep connected to Firefox (via MozRepl) since the beginning of the script, the _FFXPath() returns 0 for every object. But if I _FFDisconnect() and then _FFConnect() before reading the objects, everything is just fine!

Thought it could be important for anybody to know.. Thanks again..

Edit 2:

Now it's becoming frustrating.. If I execute this code:

#Include <FF.au3>
_FFStart("http://www.afacerilemn.ro/rom/files/detaliu_firma.php?n=A&G-ALEX-SRL&id=26366")
            $comapny = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[1]/b/font", "textContent", 9)
            $product = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[3]/td/p[@class='txt_meniu']","textContent",9)
            $language = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[6]/td/form/table[@id='AutoNumber3']/tbody/tr[1]/td/p/font[@class='txt_meniu']/u/b","textContent",9)
            $adress = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[3]/div/table[@id='AutoNumber2']/tbody/tr[1]/td[@class='txt_meniu' and position()=2]", "textContent",9)
            $telephone = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[3]/div/table[@id='AutoNumber2']/tbody/tr[2]/td[@class='txt_meniu' and position()=2]", "textContent",9)
            $fax = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[3]/div/table[@id='AutoNumber2']/tbody/tr[3]/td[@class='txt_meniu' and position()=2]", "textContent",9)
            $contactperson = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[3]/div/table[@id='AutoNumber2']/tbody/tr[4]/td[@class='txt_meniu' and position()=2]", "textContent",9)
            $site = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[3]/div/table[@id='AutoNumber2']/tbody/tr[5]/td[@class='txt_meniu' and position()=2]", "textContent",9)
            $file = FileOpen("test.csv", 1)
            FileWrite($file, $comapny & ";" & $product & ";" & $language & ";" & $adress & ";" & $telephone & ";" & $fax & ";" & $contactperson & ";" & $site & ";" &  @CRLF)
            FileClose($file)
_FFQuit()

it works as it should.. But when I execute the same code this way:

#Include <FF.au3>
_FFStart()
If _FFIsConnected() Then
For $pagenumber = 1 To 20
    $pagenonumber = "http://www.afacerilemn.ro/rom/catalog/catalog.php/cat_mobila__1/pa1__6/pa2__7/pa3__8/pa4__9/pa5__10/Country__Romania/Distribution__on/Manufacturer__on/filter__Paleti_Europaleti//pgc__"
    $pagewithnumber = $pagenonumber & $pagenumber
    _FFOpenURL($pagewithnumber)
    $detlink1="/html/body/div[2]/table[@id='AutoNumber3']/tbody/tr[3]/td[2]/div/div["
    $detlink2="]/center/font/table[@class='style1' and @id='AutoNumber1']/tbody/tr[3]/td/p/a[@class='txt_meniu']"
        For $detperpage = 1 To 10
            $detail = $detlink1 & $detperpage & $detlink2
            _FFClick(_FFXPath($detail))
            $comapny = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[1]/b/font", "textContent", 9)
            $product = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[3]/td/p[@class='txt_meniu']","textContent",9)
            $language = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[6]/td/form/table[@id='AutoNumber3']/tbody/tr[1]/td/p/font[@class='txt_meniu']/u/b","textContent",9)
            $adress = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[3]/div/table[@id='AutoNumber2']/tbody/tr[1]/td[@class='txt_meniu' and position()=2]", "textContent",9)
            $telephone = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[3]/div/table[@id='AutoNumber2']/tbody/tr[2]/td[@class='txt_meniu' and position()=2]", "textContent",9)
            $fax = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[3]/div/table[@id='AutoNumber2']/tbody/tr[3]/td[@class='txt_meniu' and position()=2]", "textContent",9)
            $contactperson = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[3]/div/table[@id='AutoNumber2']/tbody/tr[4]/td[@class='txt_meniu' and position()=2]", "textContent",9)
            $site = _FFXPath("/html/body/div[1]/table[@id='AutoNumber1']/tbody/tr[2]/td[3]/div/table[@id='AutoNumber2']/tbody/tr[5]/td[@class='txt_meniu' and position()=2]", "textContent",9)
            $file = FileOpen("test.csv", 1)
            FileWrite($file, $comapny & ";" & $product & ";" & $language & ";" & $adress & ";" & $telephone & ";" & $fax & ";" & $contactperson & ";" & $site & ";" &  @CRLF)
            FileClose($file)
            _FFAction("back")
        Next
Next
EndIf
_FFQuit()

the _FFXPath() returns 0 for every object.. Using a _FFDisconnect() and then _FFConnect()helps only if after I exit entirely from Firefox.. Could someone please explain why it happening this? Is this at the end a bug, or my code has somewhere a bug?

Edited by andrew222

Everybody starts from somewhere..

Link to comment
Share on other sites

Ok, so what I've descoverd so far is this. If I open a FF instance, _FFXPath() works as expected, as long as I don't use any other function wich could influence it's way of being. Even if I load (_FFOpenURL()) onther page, with the same HTML structure, _FFXpath still works as it should. But if I load a page, then another one (eg. click on a link on the main page, thus openening another one in the same tab), _FFXPath doesn't return anything (returns null for every query I'n asking for). I think it's about how FF.au3 functions connects to Firefox through Mozrepl.

A temporary workaround for what am I trying to do (see above), is to save the href's I need into a file or array, close the FF instance, and open another one, _FFOpenURL() the url's I fetched before, one by one, and extract the info I need. All this, becouse _FFConnect() and _FFDisconnect() doesn't make _FFXPath() to work as it should, at least not in every cases.

Like I said, this could be a temporary workaround. If anyone else facing this kind of error, or simply has something to say about it, please help, so we can help others as well.

Thank you very much,

Andrew.

Everybody starts from somewhere..

Link to comment
Share on other sites

@Mods and Admins

Sorry for posting so many times, I am not doing this to be in the first line, so sorry.

@Stilgar

Something went wrong with your last version's _FFXPath() optimization, so this must be a bug, since the very same code (see above) in V0.6.0.1 gave me strange things, as I described, but in V0.6.0.0b-5 works perfectly, so my problem solved!

Hope my "discovers" could come handy one day to someone else.. Till then,

God bless all,

Andrew.

Edited by andrew222

Everybody starts from somewhere..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...