I wish to expand all the comments under a LiveJournal post for the purposes of saving the complete thread of comments. According to LiveJournal's FAQ when a post gets more than 50 comments they are automatically collapsed and LiveJournal doesn't provide an easy way to expand them: there is no Expand All button and the user must stupidly click on the every Expand button on the web page in order to get finally all the comments expanded. I wish to automate this process using either WebUnit
or directly through NETLink
using COM/.NET interface of Chrome (or other browser).
As an example post with collapsed comments I suggest this (but feel free to take any other post if you wish):
http://suggestions.livejournal.com/825341.html
So far I have tried WebUnit
as follows without luck:
Needs["WebUnit`"]
InstallWebUnit[]
StartWebSession[];
OpenWebPage["http://suggestions.livejournal.com/825341.html"]
ClickElement[Id["t12335869"]]
The Id
"t12335869"
in the above I have found via inspection of the HTML source of the first Expand button on that web page:
<li class=" b-leaf-actions-item b-leaf-actions-expandchilds " data-tid="t12335869"> <a target="_self" href="http://suggestions.livejournal.com/825341.html?thread=12335869#t12335869" rel="nofollow" class="b-pseudo">Expand</a> </li>
I have tried also interfacing Internet Explorer via the COM interface but haven't found a way to make the click[]
method working:
Needs["NETLink`"];
InstallNET[];
ie = CreateCOMObject["InternetExplorer.Application"];
ie@visible = True;
ie@Navigate["http://suggestions.livejournal.com/825341.html"];
doc = ie@Document;
While[ie@Busy || doc@readyState =!= "complete", Pause[.1]];
all = doc@all;
elems = all@tags@"a";
Table[If[elems@item[i]@innerText === "Expand", elems@item[i]@click[];
i, ## &[]], {i, 0, elems@length - 1}] // Length
50
From the above it is seen that 50 hyperlinks with text "Expand" are found. But executing click[]
on them changes nothing.
How can I automate clicking the Expand buttons with Mathematica?