Soupify requests responses properly

This commit is contained in:
Joscha
2020-04-20 16:38:18 +00:00
parent 87395faac2
commit 6407190ae0
2 changed files with 8 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import logging
from pathlib import Path, PurePath
from typing import Optional, Tuple
import bs4
import requests
from colorama import Fore, Style
@ -30,6 +31,10 @@ def rename(path: PurePath, to_name: str) -> PurePath:
return PurePath(*path.parts[:-1], to_name)
def soupify(response: requests.Response) -> bs4.BeautifulSoup:
return bs4.BeautifulSoup(response.text, "html.parser")
def stream_to_path(response: requests.Response, to_path: Path, chunk_size: int = 1024 ** 2) -> None:
"""
Download a requests response content to a file by streaming it. This