'Azure Functions with python, html page & beautifulsoup
I am new to azure functions.
What I am trying to do is to get my azure function to open the index.html page, however I am not sure how to pass in the variable data used in my code to the html page or whether I should need something else to render the data.
My code is as follows:
import logging
import azure.functions as func
import mimetypes
from bs4 import BeautifulSoup
import requests
def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
logging.info('processed request for home function')
htmlPage = f"{context.function_directory}/index.html"
source=requests.get('https://quotes.toscrape.com/').text
soup=BeautifulSoup(source, 'lxml')
quote=soup.find('div', class_='quote')
quotetext=quote.span.text
with open(htmlPage, 'rb') as f:
mimetype = mimetypes.guess_type(htmlPage)
return func.HttpResponse(
f.read(),
mimetype=mimetype[0],
quotetext=quotetext
)
My HTML page is this:
<section class="quote">
<div class="card">
<h3>Quote</h3>
<p>{{quotetext}}</p>
</div>
</section>
I get an error "in main quotetext=quotetext". I have tried looking in various places but there is no question specific to scraping, opening the html in the trigger and displaying the quotetext variable in the html template, I would be grateful for any help
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
