From 816f222c77fd7172f71df4b6225eb43bd450ca9e Mon Sep 17 00:00:00 2001 From: rm Date: Mon, 8 Jan 2024 18:23:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PT/pt_operation.py | 10 ++++++++-- PT/test.py | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/PT/pt_operation.py b/PT/pt_operation.py index 919ccc7..70e9e62 100644 --- a/PT/pt_operation.py +++ b/PT/pt_operation.py @@ -1,4 +1,5 @@ import json +import logging import sys from loguru import logger @@ -103,7 +104,7 @@ class PtOperation: self.headers["Referer"] = url for _ in range(5): try: - response = requests.get(url, headers=self.headers, timeout=60) + response = requests.get(url, headers=self.headers, timeout=5 * 60) if response.status_code == 403 or response.text in "Just a moment": return self.flaresolverr_get(url, text) elif response.status_code == 200: @@ -119,13 +120,14 @@ class PtOperation: return "" def flaresolverr_get(self, url, text): + # 5 * 1000 * 60 代表 5分钟 for _ in range(5): try: flaresolverr_url = "http://152.136.50.100:7024/v1" payload = json.dumps({ "cmd": "request.get", "url": url, - "maxTimeout": 60000 + "maxTimeout": 5 * 1000 * 60 }) headers = { 'Content-Type': 'application/json' @@ -133,7 +135,11 @@ class PtOperation: response = requests.post(flaresolverr_url, headers=headers, data=payload) res = json.loads(response.text) if res['status'] == 'ok' and res['solution']['status'] == 200: + logging.info(f"最终耗时:{(res['endTimestamp'] - res['startTimestamp'])/ 1000 / 60:.2f} 分钟") return res['solution']['response'] + elif res['status'] == 'error': + logger.error(f"{text} , 访问返回 {res['message']} !!!") + return "" except Exception as e: time.sleep(2) else: diff --git a/PT/test.py b/PT/test.py index 94e45af..225a599 100644 --- a/PT/test.py +++ b/PT/test.py @@ -1,6 +1,9 @@ import json +import time + import requests from bs4 import BeautifulSoup + headers = { 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'accept-language': 'zh,zh-CN;q=0.9', @@ -15,7 +18,36 @@ headers = { 'upgrade-insecure-requests': '1', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', } -url = "https://totheglory.im/signup.php" +url = "https://sharkpt.net/signup.php" + + response_result = requests.get(url, headers=headers) print(response_result.status_code) -print(response_result.text) \ No newline at end of file +print(response_result.text) + + +def flaresolverr_get(url, text): + try: + flaresolverr_url = "http://152.136.50.100:7024/v1" + payload = json.dumps({ + "cmd": "request.get", + "url": url, + "maxTimeout": 5 * 1000 * 60 + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.post(flaresolverr_url, headers=headers, data=payload) + res = json.loads(response.text) + print(res) + if res['status'] == 'ok' and res['solution']['status'] == 200: + print(f"最终耗时:{(res['endTimestamp'] - res['startTimestamp'])/ 1000 / 60:.2f} 分钟") + elif res['status'] == 'error': + print(f"{text} , 访问返回 {res['message']} !!!") + return "" + except Exception as e: + print("出现错误!!!") + + +# flaresolverr_get(url, "ourbits") +