func forex() string {
client := &http.Client{
Timeout: 10 * time.Second,
}
req, err := http.NewRequest("GET", "https://www.investing.com/currencies/usd-rub", nil)
if err != nil {
log.Fatal(err)
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537")
res, err := client.Do(req)
if err != nil {
log.Println(err)
}
defer res.Body.Close()
if res.StatusCode != 200 {
log.Printf("status code error: %d %s", res.StatusCode, res.Status)
}
// Load the HTML document
doc, err := goquery.NewDocumentFromReader(res.Body)
if err != nil {
log.Println(err)
}
var price string
doc.Find("span[data-test='instrument-price-last']").Each(func(index int, item *goquery.Selection) {
price = item.Text()
fmt.Println(price)
})
return price
}