get_html.py 512 B

12345678910111213141516171819
  1. from aiohttp import ClientSession
  2. from bs4 import BeautifulSoup
  3. async def make_request(url):
  4. session = ClientSession(headers={
  5. 'application': 'LyricsGenius',
  6. 'User-Agent': 'https://github.com/johnwmillr/LyricsGenius'
  7. })
  8. resp = await session.get(url)
  9. content = await resp.read()
  10. await session.close()
  11. return content.decode("utf-8")
  12. async def get_html(url):
  13. content = (await make_request(url)).replace('<br/>', '\n')
  14. return BeautifulSoup(content, "html.parser")