Home > Software engineering >  VBA scraping of the page, that requires authentication, the related code, please check!
VBA scraping of the page, that requires authentication, the related code, please check!

Time:09-25

VBA scraping of the page data, requires authentication:

To get a website is only a PHP example, PHP language examples have these five words:

$ch=curl_init ();
Curl_setopt ($ch, CURLOPT_URL, 'https://bter.com/api/1/private/getfunds');
Curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
Curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_data);//$post_data is a random number series, such as: 'nonce=1460741026120200
Curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
Curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$res=the curl_exec ($ch);

//description: $headers form such as: {Array ([0]=& gt; KEY: public [1]=& gt; SIGN: Sha512 hash/optional parameter name=& gt; Parameter values)}
//which: Sha512 hash=hash_hmac (' Sha512, $post_data random number clearly, $secret key), is a 512 - bit hash value, to verify
//send the two data is mainly get JSON format of the data stored in $res, POST parameters submitted way,


To the VBA in: (I find this code on the net, don't know can use, or other code can also be)
 Sub (XXX) 
Dim HTTP
Set the HTTP=CreateObject (" Microsoft. XMLHTTP ")
HTTP. Open the "POST", "http://url/PHP file name. PHP", False
HTTP. Send "T1=XXX& T2=XXXXX& T3=XXXXXX "
If HTTP. Status=200 Then
[a1]=HTTP. The responseText
MsgBox "success,"
The Else
MsgBox "call fails, the error code:" & amp; . HTTP Status
End the If
End Sub


To my understanding: "in the VBA T1=XXX& T2=XXXXX& T3=XXXXXX ", is refers to in PHP $headers, right? But the $post_data data should be placed on what is the position of VBA code?
The two data transfer in a PHP: $post_data, $headers, how to transmit in the VBA?

CodePudding user response:

Don't be A language code is modified to B language code busywork,
Also don't use A language code to directly invoke B language code base, this complicated things so easy to get wrong,
Just make A, B language code of input and output is redirected to A text file, or modify A, B language code let it through text file input and output,
Can easily make A, B coordination between the two languages,
For example:
A will request data written to A file a.t xt, renamed after finish aa. TXT
B find aa. TXT, read its contents, call the corresponding function, and writes the results file b.t xt, after finish delete aa. TXT, changed its name to bb. TXT
Found A bb. TXT, read the content, after finish delete bb. TXT
Above can be replaced by any kind of A language or development environment, B can be replaced by any kind of with the development of A different language or development environment,
Unless A or B does not support to determine whether A file exists, file read and write and file name,
But who can name does not support to determine whether a file exists, file read and write and file name for the development of language or development environment?
Can put the temporary files on the RamDisk efficiency decrease wear disk,
Data structure is very complex, a text file format problems refer to a json or XML

The communication methods between the temporary text file sharing this process there are plenty of advantages, compared to other method only listed below I can think of now:
Loose coupling between process,
Can be on the same machine, process, also can cross machine, across the operating system, hardware platform, and even multinational,
, convenient debugging, and monitoring, only let the third party or artificial view the temporary text files,
Switch, convenient online service, need to delete or create the temporary text files,
, is convenient to realize distributed and load balancing,
Services to provide convenient, queue, queue is full and it is almost impossible to happen (unless the hard disk space full)
DE...

"Across different languages, machine, across the operating system, hardware platform, multinational, cross *. *" this suffering,
back "exchange of information using Shared plain text file" shore!
  •  Tags:  
  • VBA
  • Related