summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2022-04-17 20:23:52 -0600
committermo khan <mo@mokhan.ca>2022-04-17 20:23:52 -0600
commit83dcd54b70df5deeb151ee6b49fb3a75a3bac62c (patch)
tree96e13f73e59715db22667c6dd4b285047c27dfd4
initial commit
-rw-r--r--go.mod5
-rw-r--r--go.sum2
-rw-r--r--main.go44
3 files changed, 51 insertions, 0 deletions
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..b00871b
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,5 @@
+module github.com/xlgmokha/tick
+
+go 1.18
+
+require golang.org/x/net v0.0.0-20220412020605-290c469a71a5
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..9ceb85a
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,2 @@
+golang.org/x/net v0.0.0-20220412020605-290c469a71a5 h1:bRb386wvrE+oBNdF1d/Xh9mQrfQ4ecYhW5qJ5GvTGT4=
+golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..e2102e5
--- /dev/null
+++ b/main.go
@@ -0,0 +1,44 @@
+package main
+
+import (
+ "fmt"
+ "net/http"
+ "os"
+ "strings"
+
+ "golang.org/x/net/html"
+)
+
+func MapFrom(attrs []html.Attribute) map[string]string {
+ m := map[string]string{}
+ for _, attr := range attrs {
+ m[attr.Key] = attr.Val
+ }
+ return m
+}
+
+func Visit(n *html.Node) {
+ if n.Type == html.ElementNode && n.Data == "fin-streamer" {
+ m := MapFrom(n.Attr)
+ if m["data-field"] != "" && strings.Contains(m["data-field"], "Price") {
+ fmt.Printf("%v: %s\n", m["data-symbol"], m["value"])
+ }
+ }
+
+ for c := n.FirstChild; c != nil; c = c.NextSibling {
+ Visit(c)
+ }
+}
+
+func main() {
+ response, err1 := http.Get("https://finance.yahoo.com/quote/MSFT/")
+ if err1 != nil {
+ os.Exit(1)
+ }
+
+ doc, err := html.Parse(response.Body)
+ if err != nil {
+ os.Exit(2)
+ }
+ Visit(doc)
+}