Last active
June 4, 2022 15:12
-
-
Save Igouist/039148b1aaaa8e3073f5e135ff689f9b to your computer and use it in GitHub Desktop.
使用 AngleSharp + Yahoo 股市來抓取目標股票的當日資訊
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async Task Main() | |
{ | |
var key = "2330"; | |
var url = $"https://tw.stock.yahoo.com/quote/{key}"; | |
var config = AngleSharp.Configuration.Default.WithDefaultLoader( | |
new LoaderOptions | |
{ | |
IsResourceLoadingEnabled = true | |
}); | |
var browser = BrowsingContext.New(config); | |
var document = await browser.OpenAsync(url); | |
var tables = document?.QuerySelectorAll("li.price-detail-item"); | |
document.Close(); | |
tables.ToDictionary( | |
t => t.FirstChild.TextContent, // 欄位名稱 ex: 開盤價 | |
t => t.LastChild.TextContent) // 欄位數值 ex: 500 | |
.Dump(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment