Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,054 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How to fetch the HTML Code from the website using Azure Functions, below code I have tried but not getting the result!
CSharp
using (var client = new WebClient ())
{
log.LogInformation($"Fetching html from {URL}");
try
{
var response = client.DownloadString(URL);
baseHtmlBasePageList.Add(response);
}
catch(Exception ex)
{
log.LogError(ex.Message);
}
}
@NFSCoder-9821 Thanks for reaching out and apology for the delay. The query is more towards C# rather than azure function. I have leveraged the code below and I can see the HTML text return from my test webpage. I am not sure what the type of baseHtmlBasePageList
that you have defined in your code.
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Net.Http.Headers;
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string url = "https://google.com";
HttpClient client = new HttpClient();
using HttpResponseMessage response = await client.GetAsync(url);
using HttpContent content = response.Content;
string pageContent = await content.ReadAsStringAsync();
return new OkObjectResult(pageContent);
}