Carlos Ortega
Carlos Ortega
CC#
Created by Carlos Ortega on 4/15/2024 in #help
I'm trying to WebScrap data from a currency website.
I don't really know how to get the specific span that I'm trying to get here.
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using HtmlAgilityPack;
using static System.Net.WebRequestMethods;

namespace ReadDataFromWebsite
{
class Program
{
static void Main(string[] args)
{
String url = "https://www.eldolar.info/es-MX/mexico/dia/hoy";
var httpClient = new HttpClient();
var html = httpClient.GetStringAsync(url).Result;
var htmldocument = new HtmlDocument();
htmldocument.LoadHtml(html);

var divs = htmldocument.DocumentNode.Descendants("span")
.Where(node => node.GetAttributeValue("class", "data-x")
.Contains("xTimes")).ToList();



foreach ( var div in divs )
{
Console.WriteLine(div.InnerText.Trim());
}

//var htmlNodes = htmldocument.DocumentNode.SelectSingleNode("//body/h1");

//var dolar = htmldocument.DocumentNode.SelectSingleNode("//tbody/div[@id='tdSF43718']");
//var dolarfin= dolar.InnerText;
//Console.WriteLine(dolarfin);


}
}

}
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using HtmlAgilityPack;
using static System.Net.WebRequestMethods;

namespace ReadDataFromWebsite
{
class Program
{
static void Main(string[] args)
{
String url = "https://www.eldolar.info/es-MX/mexico/dia/hoy";
var httpClient = new HttpClient();
var html = httpClient.GetStringAsync(url).Result;
var htmldocument = new HtmlDocument();
htmldocument.LoadHtml(html);

var divs = htmldocument.DocumentNode.Descendants("span")
.Where(node => node.GetAttributeValue("class", "data-x")
.Contains("xTimes")).ToList();



foreach ( var div in divs )
{
Console.WriteLine(div.InnerText.Trim());
}

//var htmlNodes = htmldocument.DocumentNode.SelectSingleNode("//body/h1");

//var dolar = htmldocument.DocumentNode.SelectSingleNode("//tbody/div[@id='tdSF43718']");
//var dolarfin= dolar.InnerText;
//Console.WriteLine(dolarfin);


}
}

}
If you execute my code basically you will get like 4 numbers, I need to get only the second one.
6 replies