Hello guys. I'm trying to make a web scraper, but this error appears in GetAsync (). Does anyone know for what reason?
Thanks
The code:
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using AngleSharp;
using AngleSharp.Html.Parser;
namespace web_scraper.Controllers
{
[Route("[controller]")]
[ApiController]
public class WebScraperController : ControllerBase
{
private readonly ILogger<WebScraperController> _logger;
public WebScraperController(ILogger<WebScraperController> logger)
{
_logger = logger;
}
[HttpGet]
public async Task<string> GetAsync() //O erro aparece aqui em GetAsync()
{
var config = Configuration.Default.WithDefaultLoader();
var context = BrowsingContext.New(config);
var document = await context.OpenAsync("https://www.americanas.com.br/produto/1951947793?opn=YSMESP&sellerid=23060006000150&epar=bp_pl_00_go_tel_smartphone_todas_geral_gmv&WT.srch=1&acc=e789ea56094489dffd798f86ff51c7a9&i=5d32878c49f937f6252da60d&o=5f3bf3b0f8e95eac3dd8a860&gclid=CjwKCAiAhbeCBhBcEiwAkv2cYx7Q2RhUaBWOLTd3CimKTQeF7d3uum9gohFS2DeUICC_7lvivUHmyBoCOn4QAvD_BwE");
_logger.LogInformation(document.DocumentElement.OuterHtml);
}
}
}
The error mensage:
"WebScraperController.GetAsync()": nem todos os caminhos de código retornam um valor
The error, "Not all code paths return a value", is very clear. You've defined the action method to return a string but the method body does not return a string.
None
0 Points
3 Posts
WebScraping in asp.net core 3.1
Mar 15, 2021 12:26 PM|eduardofnawusjdnfa|LINK
Hello guys. I'm trying to make a web scraper, but this error appears in GetAsync (). Does anyone know for what reason?
Thanks
The code:
The error mensage:
All-Star
53711 Points
24035 Posts
Re: WebScraping in asp.net core 3.1
Mar 15, 2021 12:31 PM|mgebhard|LINK
The error, "Not all code paths return a value", is very clear. You've defined the action method to return a string but the method body does not return a string.
C# Programming Guide.
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/methods
None
0 Points
3 Posts
Re: WebScraping in asp.net core 3.1
Mar 15, 2021 02:18 PM|eduardofnawusjdnfa|LINK
thanks, with your comment i managed to understand the code better and fixed the error.
None
0 Points
3 Posts
Re: WebScraping in asp.net core 3.1
Mar 15, 2021 02:20 PM|eduardofnawusjdnfa|LINK
The right code: