mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-24 18:40:03 +08:00
明确get json与get xml
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from .request_url import RequestURL
|
||||
from module.conf import settings
|
||||
|
||||
@@ -17,7 +19,7 @@ class TorrentInfo:
|
||||
class RequestContent(RequestURL):
|
||||
# Mikanani RSS
|
||||
def get_torrents(self, _url: str) -> [TorrentInfo]:
|
||||
soup = self.get_content(_url)
|
||||
soup = self.get_xml(_url)
|
||||
torrent_titles = [item.title.string for item in soup.find_all("item")]
|
||||
torrent_urls = [item.get("url") for item in soup.find_all("enclosure")]
|
||||
torrents = []
|
||||
@@ -27,11 +29,14 @@ class RequestContent(RequestURL):
|
||||
return torrents
|
||||
|
||||
def get_torrent(self, _url) -> TorrentInfo:
|
||||
soup = self.get_content(_url)
|
||||
soup = self.get_xml(_url)
|
||||
item = soup.find("item")
|
||||
enclosure = item.find("enclosure")
|
||||
return TorrentInfo(item.title.string, enclosure["url"])
|
||||
|
||||
def get_xml(self, url):
|
||||
return BeautifulSoup(self.get_url(url).text, "xml")
|
||||
|
||||
# API JSON
|
||||
def get_json(self, _url) -> dict:
|
||||
return self.get_content(_url, content="json")
|
||||
return self.get_url(_url).json()
|
||||
|
||||
@@ -5,8 +5,6 @@ import socket
|
||||
import socks
|
||||
import logging
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from module.conf import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -37,12 +35,6 @@ class RequestURL:
|
||||
logger.debug(e)
|
||||
break
|
||||
|
||||
def get_content(self, url, content="xml"):
|
||||
if content == "xml":
|
||||
return BeautifulSoup(self.get_url(url).text, content)
|
||||
elif content == "json":
|
||||
return self.get_url(url).json()
|
||||
|
||||
def __enter__(self):
|
||||
self.session = requests.Session()
|
||||
if settings.proxy.enable:
|
||||
|
||||
Reference in New Issue
Block a user