freeports_analysis.download

Functions for downloading PDF files from the internet and web scraping.

Functions

download_pdf(url[, pdf])

Download PDF file from URL and optionally save to local filesystem.

freeports_analysis.download.download_pdf(url: str, pdf: Path | None = None) BytesIO

Download PDF file from URL and optionally save to local filesystem.

Parameters:
  • url (str) – Unique resource identifier on internet pointing to PDF file

  • pdf (Optional[Path], optional) – Path where to save the PDF in filesystem, by default None

Returns:

Byte stream with input/output operations like a file object

Return type:

BytesIO

Raises:

requests.RequestException – If the HTTP GET call fails or returns an error status code

Notes

If pdf is provided, the downloaded PDF will be saved to that path in addition to being returned as a BytesIO stream. The function uses a 10-second timeout for the HTTP request.