0
I’m trying to get a text from another site using C# (Htmlagilitypack).
I can find the div, but when I try to show the value on the screen, it shows the path of the function.
I believe I’m forgetting some piece of code.
Follow my Controller:
public class TesteDeScrapingController : Controller
{
// GET: TesteDeScraping
public ActionResult Index()
{
HtmlWeb web = new HtmlWeb();
HtmlDocument html = web.Load("https://www.climatempo.com.br/previsao-do-tempo/cidade/583/araguaina-to");
var div = html.DocumentNode.SelectNodes("//p[@id='tempMax0']");
ViewBag.Div = div;
return View();
}
}
Follows my HTML:
<h2>Teste</h2>
<div>
@ViewBag.Div
</div>
doing this you inside your div will be like picking up a Documentnode and calling the Tostring() method on it. I think you just call the property
InnerHtml
:@ViewBag.Div.InnerHtml
– Rovann Linhalis
@Rovannlinhalis function bears the name of the Collection. I managed to solve, I will post as an answer if anyone needs in the future. Thanks for the help!
– Diego Grossi
It has no direct relation to your doubt, but in the case of the given example, weather, they have an API to access the data, without the need to read this HTML: http://apiadvisor.climatempo.com.br/doc/index.html
– Dudaskank