2 single: RingLibCurl; はじめに
11 pair: RingLibCurl; Get リクエスト
22 curl = curl_easy_init()
24 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1)
25 curl_easy_setopt(curl, CURLOPT_URL, "http://ring-lang.sf.net")
27 curl_easy_perform(curl)
29 curl_easy_cleanup(curl)
33 pair: RingLibCurl; Post リクエスト
44 curl = curl_easy_init()
46 cPostThis = "page=4&Number1=4&Number2=5"
47 curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/ringapp/index.ring?page=3")
48 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, cPostThis)
50 curl_easy_perform(curl)
52 curl_easy_cleanup(curl)
55 pair: RingLibCurl; Facebook へのログイン
66 see "Enter Email : " give $login_email
67 See "Enter Password : " give $login_pass
69 curl = curl_easy_init()
71 curl_easy_setopt(curl, CURLOPT_URL, 'https://www.facebook.com/login.php')
72 curl_easy_setopt(curl, CURLOPT_POSTFIELDS,'charset_test=j u s t a t e s t'+
73 ' &email='+urlencode($login_email)+'&pass='+
74 urlencode($login_pass)+'&login=Login')
75 curl_easy_setopt(curl, CURLOPT_POST, 1)
76 curl_easy_setopt(curl, CURLOPT_HEADER, 0)
77 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1)
78 curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt")
79 curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookies.txt")
80 curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U;"+
81 " Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3")
82 curl_easy_setopt(curl, CURLOPT_REFERER, "http://www.facebook.com")
83 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE)
84 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2)
86 mylist = curl_slist_append(NULL,'Accept-Charset: utf-8')
87 curl_slist_append(mylist,'Accept-Language: en-us,en;q=0.7,bn-bd;q=0.3')
88 curl_slist_append(mylist,'Accept: text/xml,application/xml,'+
89 'application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5')
90 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, mylist)
92 curl_easy_setopt(curl, CURLOPT_COOKIESESSION, false)
94 curl_easy_perform(curl)
96 curl_easy_cleanup(curl)
106 cOut += "%"+str2hex(x)
112 pair: RingLibCurl; 実行結果を文字列で保存
115 ======================
123 curl = curl_easy_init()
125 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1)
126 curl_easy_setopt(curl, CURLOPT_URL, "http://ring-lang.sf.net")
128 cOutput = curl_easy_perform_silent(curl)
133 curl_easy_cleanup(curl)
136 pair: RingLibCurl; Yahoo! から株式情報を取得
139 =========================
147 ### 第一部 --- 断片とクッキーの取得 -----------------------------------------
149 See "Start curl_easy_init(): "+ nl
150 curl = curl_easy_init() ### >>> HANDLE >>> 01006BD0 CURL 0
152 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1)
153 curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt")
154 curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookies.txt")
155 curl_easy_setopt(curl, CURLOPT_URL, "https://finance.yahoo.com/quote/AMZN/history")
157 ### HTML データ >>> STDOUT Window では curl_easy_perform_silent >>> String を使用。
159 cOutput = curl_easy_perform_silent(curl) ### データの取得 >>> String
162 ### データから断片 (Crumb) を抽出します。
163 ### "CrumbStore":{"crumb":"abcdefghijk"},
167 newStr1 = substr(cOutput, substr(cOutput, '"CrumbStore":{"crumb":"' ), 48 )
168 nPosS = substr(newStr1, ':"' ) ; ### crumb -2 の始点
169 nPosE = substr(newStr1, '"}' ) ; ### crumb の終点
170 nCount = nPosE - nPosS -2 ### crumb の大きさ
171 myCrumb = substr(newStr1, nPosS +2, nCount)
173 See "myCrumb.: |"+ myCrumb +"|" +nl
175 ### UniCode の "\u002F" を "/" へ置換します。
176 if substr( myCrumb, "\u002F")
177 myCrumb = substr( myCrumb, "\u002F", "/")
178 See "myCrumb2: |"+ myCrumb +"|"+ nl
182 See "No Connectivity to Yahoo. Looking for Cookie and Crumb." +nl +nl
186 ### 第二部 --- URL へ断片とクッキーを送信 ----------------------------------------------
188 ### Yahoo! へ URL+断片を送信して最初の株式履歴情報を取得します。
190 $url = "https://query1.finance.yahoo.com/v7/finance/download/AMZN"+
191 "?period1=1277856000&period2=1498777545&interval=1wk" +
192 "&events=history&crumb=" + myCrumb
194 curl_easy_setopt(curl, CURLOPT_URL, $url);
195 cStr = curl_easy_perform_silent(curl)
198 curl_easy_cleanup(curl) ### cURL を閉じるのを忘れないように。
205 myCrumb.: |sEEeW97mxvN|
206 Date,Open,High,Low,Close,Adj Close,Volume
207 2010-07-05,110.650002,117.480003,109.000000,117.260002,117.260002,21000400
208 2010-07-12,117.809998,124.879997,117.320000,118.489998,118.489998,29407300
209 2010-07-19,118.379997,121.250000,105.800003,118.870003,118.870003,74252100