發表文章

目前顯示的是 2月, 2021的文章

利用Google sheet 的Importxml 函式抓取 上櫃/興櫃 股票資料

圖片
   Googlefinance() 函數在抓取上市股票資料非常方便,但是目前不支援上櫃與興櫃的股票代號。 這裡我們利用 Importxml() 這個函式來彌補這方便的資訊。 首先要找一個網站可以拿到上櫃/興櫃股價資訊,這裡以香港的yahoo finance 為例 ex. 上櫃股票代號:3088,網址為: https://hk.finance.yahoo.com/quote/3088.TWO/ 使用google chrome開啟這個網址,並選取要抓取的價格,再按右鍵點選"檢查",Chrome會顯示原始碼視窗;在要抓取的欄位上按右鍵選擇"Copy" - "Copy XPath"。 複製下來的XPath為 "//*[@id="quote-header-info"]/div[3]/div[1]/div/span[1]" 將雙引號改為單引號:" //*[@id=’quote-header-info’]/div[3]/div[1]/div/span[1] " 在googlesheet中使用IMPORTXML(網址, XPath_查詢)函數,輸入網址與XPath就可以擷取到上櫃股價 把股票代號拉出來當作變數,再利用CONCATENATE()函式組合字串,就完成了。 參考範例檔案連結: Example of Importxml