5
$\begingroup$

With WebExcute, I have been able to get access to a particular url https://www.hkex.com.hk/eng/sorc/options/statistics_hv_iv.aspx

However, in this url, there is a quite a number of stock code that one can select and then click to download the data. For example, to pick the stock code of (00700) Tencent and download the associated data.

My question is what will be the command to perform the above steps.

Thanks

Alan

$\endgroup$

1 Answer 1

5
$\begingroup$

Update

To get the list of codes and company names

WebExecute[session, "ElementText" -> #] & /@ 
 WebExecute[session, "LocateElements" -> "Tag" -> "option"]

{(00001) CKH Holdings,(00002) CLP,(00003) HK & China Gas,(00004) Wharf,(00005) HSBC,(00006) Power Assets,(00011) Hang Seng Bank,(00012) Henderson Land,(00016) SHK Properties,(00017) New World Dev,(00019) Swire Pacific-A,(00023) Bank Of East Asia,(00027) Galaxy,(00066) MTR Corp,(00135) Kunlun Energy,(00151) Want Want China,(00175) Geely Auto,(00267) Citic,(00293) Cathay Pacific,(00358) Jiangxi Copper,(00386) Sinopec,(00388) HKEX,(00390) China Railway,(00489) Dongfeng Group,(00494) Li & Fung,(00688) China Overseas,(00700) Tencent,(00728) China Telecom,(00753) Air China,(00762) China Unicom,(00788) China Tower Corporation Limited,(00823) Link REIT,(00857) PetroChina,(00883) CNOOC,(00902) Huaneng Power,(00914) Anhui Conch,(00939) CCB,(00941) China Mobile,(00992) Lenovo Group,(00998) Citic Bank,(01044) Hengan Int'l,(01088) China Shenhua,(01093) CSPC Pharmaceutical,(01099) Sinopharm,(01109) China Res Land,(01113) CK Asset,(01171) Yanzhou Coal,(01186) China Rail Cons,(01211) BYD,(01288) ABC,(01299) AIA,(01336) NCI,(01339) PICC Group,(01359) China Cinda,(01398) ICBC,(01658) PSBC,(01800) China Comm Cons,(01810) XiaoMi Corporation,(01816) CGN Power,(01876) Budweiser APAC,(01898) China Coal,(01918) Sunac,(01928) Sands China,(01988) Minsheng Bank,(02007) Country Garden,(02018) AAC Tech,(02202) China Vanke,(02238) GAC Group,(02282) MGM China,(02318) Ping An,(02319) Mengniu Dairy,(02328) PICC,(02333) Greatwall Motor,(02382) Sunny Opt,(02388) BOCHK,(02600) Chalco,(02601) CPIC,(02628) China Life,(02777) Guangzhou R&F,(02800) Tracker Fund,(02822) CSOP A50 ETF,(02823) X iShares A50,(02828) HS H-Share ETF,(02888) Stan Chart,(02899) Zijin Mining,(03188) CAM CSI300 ETF,(03323) CNBM,(03328) BoComm,(03333) China Evergrande Group,(03690) Meituan Dianping,(03888) Kingsoft,(03968) CM Bank,(03988) Bank of China,(06030) Citic Sec,(06837) Haitong Sec,(09988) Alibaba}


If you know the code number e.g. 00700 then you can download the CSV with the data.

session = StartWebSession[];

(* The code is in the URL *)
WebExecute[session, 
 "OpenPage" -> 
  "https://www.hkex.com.hk/eng/sorc/options/statistics_hv_iv.aspx?ucode=00700"];

exportElement = WebExecute[session, "LocateElements" -> "HyperlinkText" -> "Export to CSV"];

WebExecute[session, "ClickElement" -> exportElement]

DeleteObject[session];

The file "statistics_hv_iv.csv" is downloaded to your browsers default download directory.

$\endgroup$
4
  • $\begingroup$ Rohit, Thanks for your reply and I can now download the CSV file. However, the file extension is with .csv.crdownload (I can just rename it to .csv manually). But some times it will long name such as cee46dbb-fc91-4cec-97e6-8a801ea5b96d.tmp. If I reset the kernal every time, the file will be with .csv.crdownload. $\endgroup$
    – Akcmok
    Commented Dec 28, 2019 at 15:23
  • $\begingroup$ Usually in Chrome an extension of crdownload means that the file download has not completed. Try waiting before executing DeleteObject[session]. $\endgroup$ Commented Dec 28, 2019 at 15:38
  • $\begingroup$ Rohit, I solved the file name problem by adding a Pause[1] command after the url is opened. Then all the file name is normal. Thanks for your help. Alan $\endgroup$
    – Akcmok
    Commented Dec 30, 2019 at 7:07
  • $\begingroup$ @Akcmok You are welcome. Could you please accept my answer if it is satisfactory or let me know if there is anything missing. Thanks. $\endgroup$ Commented Dec 31, 2019 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.