load "libcurl.ring"
###------------------------------
### Get Request¶
fh = Fopen("fileYahooData.out","w")
See nl + nl +"===== GET REQUEST ====="+ nl +nl
### Part 1 --- Get Crumb and Cookie -----------------------------------------
curl = curl_easy_init() ### >>> HANDLE >>> 01006BD0 CURL 0
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) ### No output
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt") ### No output, Result to File
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookies.txt") ### No output, Result to File
curl_easy_setopt(curl, CURLOPT_URL, "https://finance.yahoo.com/quote/AMZN/history") ### No output
# curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write) ### ??? How do you do this
# curl_easy_setopt(curl, CURLOPT_WRITEDATA, &write_result)) ### ???
### >>> HTML Data to STDOUT Window
### Find: CrumbStore in StdOut, Cookie is in cookies.txt
### "CrumbStore":{"crumb":"a07fAG9jmUy"}
result = curl_easy_perform(curl) ### >>> 005F4250 CURLcode 0
See nl +nl +"===== URL Call: Result ======="+nl ; See result ; See nl +"============"+ nl +nl
### Part 2 --- Send URL with Crumb, and Cookie -----------------------------------------
myCrumb = "a07fAG9jmUy"
myCookie = "16n00i9cj0nj1&b=3&s=vq"
$url = "https://query1.finance.yahoo.com/v7/finance/download/AMZN?period1=1464726832&period2=1496262832&interval=1wk&events=history&crumb="+ myCrumb
$url2 = "https://query1.finance.yahoo.com/v7/finance/download/NVDA?period1=1464811233&period2=1496347233&interval=1wk&events=history&crumb="+ myCrumb
### Send URL and Cookie to Yahoo to fetch stock history data
### Cookie and AMZN
curl_easy_setopt(curl, CURLOPT_COOKIE, myCookie);
curl_easy_setopt(curl, CURLOPT_URL, $url);
curl_easy_perform(curl)
### NVDA
curl_easy_setopt(curl, CURLOPT_URL, $url2);
curl_easy_perform(curl)
### Part 3 --- Try Download() -----------------------------------------
See nl +"===== TRY Dowload(): =========="+ nl
cStr = download($url) ### <<<== URL
write("download.txt", cStr) ### Write data to file
See nl +"===== Back from download: ====="+ nl
See cStr
curl_easy_cleanup(curl) ### No output
See nl +"=========== END ==============="+ nl
curl_easy_perform_silent()
Exampleload "libcurl.ring"
curl = curl_easy_init()
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1)
curl_easy_setopt(curl, CURLOPT_URL, "http://ring-lang.sf.net")
cOutput = curl_easy_perform_silent(curl)
See "Output:" + nl
see cOutput
curl_easy_cleanup(curl)
To play with the output (The String)
use SubStr()
* To find a substring position
* To Get Substring
See Documentation : http://ring-lang.sourceforge.net/doc1.3/strings.html#substr-function
Example# cHTML contains the HTML file
# Get the text starting from what we want
NewStr = substr(cHTML, substr(cHTML, '"CrumbStore":{"crumb":"' ) )
Then continue using SubStr() to remove text around what you want.
It will be simple in two lines of code.
Greetings,
Mahmoud