Discussion:
How to simulate (button click that invokes) javascript using wininet
(too old to reply)
Liam moc
2008-07-23 11:42:04 UTC
Permalink
I've been using internetopenurl / internetreadfile to retrieve web pages
no problem however one page contains the following



/////entry near start of form

<script type="text/javascript"> <!--

vBulletin_Clock = new _vBulletin_Clock;
... more stuff ...

detail_loader = new Array();

--> </script>

///////later in the form are multiple instances of

<script type="text/javascript">
<!--detail_loader[detail_loader.length] = new Array('detail_load_8072',
'8072', 'Open Detail', '1', '1');-->
</script>


obviously each instance has different params. These are associated with
images(buttons) on the form and when clicked add a new frame of text to
the form. Note that this new text is not available within the source of
the the parent form.

So my question is how do I prepare a request to retreive this data?

Can I use InternetOpenUrl specifying the script and params in the
lpszHeaders param.
If so how do I format the string ?
Can I query the format of this header string from the site ?


Having searched around I came across and tried the following but I'm not
sure if I'm anywhere close to what i'm trying to achieve. I think I'm
tryin to get the required parameters format but ?!?!?

(coded In Delphi. All nullstring casting removed)

hInternetOpen := InternetOpen
('httpgeneric',INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);

hInternetConnect := InternetConnect
(hInternetOpen,'http://www.forexfactory.com/',INTERNET_DEFAULT_HTTP_PORT
,nil,'HTTP/1.0',INTERNET_SERVICE_HTTP,0,0);

hHttpOpenRequest := HttpOpenRequest
(hInternetConnect,'POST','scripts/detail_loader.asp','HTTP/1.0',nil,0,IN
TERNET_FLAG_RELOAD,0);

sHeader := 'Content-Type: application/x-www-form-urlencoded'+#13#10;

bRet := HttpAddRequestHeaders(hHttpOpenRequest,sHeader, Length(sHeader),
HTTP_ADDREQ_FLAG_REPLACE Or HTTP_ADDREQ_FLAG_ADD);

///// bret returns true here ... so far so good ?
/// I Dont know what Im really requesting with the value in the sHeader


...... after here ive tried

bRet := HttpQueryInfo(hHttpOpenRequest,
HTTP_QUERY_RAW_HEADERS_CRLF,buf, maxl,tr);

/// hoping to get the param names returned but it returns false



...... ive also tried this just trying to pass the params

lpszPostData := 'detail_load_8072&8072&open detail&1&1';
lPostDataLen := Length(lpszPostData);

bRet := HttpSendRequest
(hHttpOpenRequest,nil,0,lpszPostData,lPostDataLen);


//// Returns false .. Am I close here ? Is it just a case of supplying
an lpszPostData in the correct format?

Im hoping after calling HttpSendRequest I can use InternetReadFile to
retrieve the data i want to get at.

Any help here will be much apreciated
Dan Mitchell
2008-07-31 21:34:24 UTC
Permalink
Post by Liam moc
So my question is how do I prepare a request to retreive this data?
Can I use InternetOpenUrl specifying the script and params in the
lpszHeaders param.
Nope, you'll need to actually execute the javascript and get the URL out
that way. You can use spidermonkey from mozilla for that, or another
javascript interpreter if you'd rather. You'll still have to write code to
retrieve the various sub-files so that all the bits of javascript required
are available, and you'll need to search/hook any relevant javascript
calls that pull in other web pages or suchlike while it's evaluated.

-- dan
Liam moc
2008-09-03 23:22:11 UTC
Permalink
Post by Dan Mitchell
Post by Liam moc
So my question is how do I prepare a request to retreive this data?
Can I use InternetOpenUrl specifying the script and params in the
lpszHeaders param.
Nope, you'll need to actually execute the javascript and get the URL out
that way. You can use spidermonkey from mozilla for that, or another
javascript interpreter if you'd rather. You'll still have to write
code to retrieve the various sub-files so that all the bits of
javascript required are available, and you'll need to search/hook any
relevant javascript calls that pull in other web pages or suchlike
while it's evaluated.
-- dan
OK thanks for the shove in the right direction & apols for the late
reply

I've downloaded spidermonkey and hopefully will be on the case soon ..
Just trying to get VS C++ sorted out and .net up to date has held me
back for a while.

I'll post back here if I make some usable headway. Else I guess theres a
spidermonky group that'll fit my bill better.

regards

Loading...