mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-08 03:54:26 +08:00
Lukazlim: Replace dependency requests
with httpx
(#12744)
* Replace dependency `requests` with `httpx` Fixes #12742 Signed-off-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com> * updating DIRECTORY.md * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com> Co-authored-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com> Co-authored-by: cclauss <cclauss@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,6 +1,15 @@
|
||||
# /// script
|
||||
# requires-python = ">=3.13"
|
||||
# dependencies = [
|
||||
# "beautifulsoup4",
|
||||
# "fake-useragent",
|
||||
# "httpx",
|
||||
# ]
|
||||
# ///
|
||||
|
||||
import os
|
||||
|
||||
import requests
|
||||
import httpx
|
||||
from bs4 import BeautifulSoup
|
||||
from fake_useragent import UserAgent
|
||||
|
||||
@ -12,7 +21,7 @@ def save_image(image_url: str, image_title: str) -> None:
|
||||
"""
|
||||
Saves the image of anime character
|
||||
"""
|
||||
image = requests.get(image_url, headers=headers, timeout=10)
|
||||
image = httpx.get(image_url, headers=headers, timeout=10)
|
||||
with open(image_title, "wb") as file:
|
||||
file.write(image.content)
|
||||
|
||||
@ -22,7 +31,7 @@ def random_anime_character() -> tuple[str, str, str]:
|
||||
Returns the Title, Description, and Image Title of a random anime character .
|
||||
"""
|
||||
soup = BeautifulSoup(
|
||||
requests.get(URL, headers=headers, timeout=10).text, "html.parser"
|
||||
httpx.get(URL, headers=headers, timeout=10).text, "html.parser"
|
||||
)
|
||||
title = soup.find("meta", attrs={"property": "og:title"}).attrs["content"]
|
||||
image_url = soup.find("meta", attrs={"property": "og:image"}).attrs["content"]
|
||||
|
Reference in New Issue
Block a user