Extract JavaScript Generated Links in Delphi
I'm working on a piece of code in which I require to extract all links from a particular web page. I use the component EmbeddedWB because I need to show the current page as well. I have a simple page that is loaded into the EmbeddedWB and contains some scripts that generates some URLs using the function "document.write" of JavaScript. Theoretically I have something like this:
<html>
<body>
<a href=#>No problem Here<a/>
<script Language="JavaScript">
var random=Math.floor(Math.random()*11);
document.write("<a href=\"index"+random+".html\"> I Can’t catch this link! </a>");
</script>
</body>
</html>
By using the function ViewPageLinksToStrings (LinksList: TStrings) of the component I get as expected the URL’s found in the source code, but my intention is to catch the links that are gene开发者_StackOverflow中文版rated with JavaScript too.
What would be the best way to do this? There is any library I can use?
Thank you for your time. John Marko
It looks like EmbeddedWB supports Javascript and I found this article in the forum. I contains code which reads the full (Javascript-generated) DOM tree into a variable of type IHTMLDocument2, which is simplified here:
procedure MyProcedure(Sender: TObject);
var
Doc: IHTMLDocument2;
begin
EmbeddedWB1.Navigate('... some url ...');
while EmbeddedWB1.ReadyState < READYSTATE_INTERACTIVE do
Application.ProcessMessages;
Doc := EmbeddedWB1.Document as IHTMLDocument2;
...
精彩评论