From 816559cffc1cf69a6d46633dd7feb6d0f4a0eed4 Mon Sep 17 00:00:00 2001 From: ngfchl Date: Fri, 25 Nov 2022 18:46:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=BB=A3=E7=A0=81=EF=BC=9A?= =?UTF-8?q?=E7=88=AC=E5=8F=96=E5=86=85=E5=AE=B9=E4=BD=BF=E7=94=A8=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89User-Agent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt_site/UtilityTool.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/pt_site/UtilityTool.py b/pt_site/UtilityTool.py index fe6b41f..ce4e5f3 100644 --- a/pt_site/UtilityTool.py +++ b/pt_site/UtilityTool.py @@ -88,18 +88,9 @@ class MessageTemplate: class PtSpider: """爬虫""" - def __init__(self, browser='chrome', platform='darwin', - user_agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ' - 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.42', - *args, **kwargs): + def __init__(self, browser='chrome', platform='darwin', *args, **kwargs): self.browser = browser self.platform = platform - self.headers = { - 'User-Agent': user_agent, - # 'Connection': 'close', - # 'verify': 'false', - # 'keep_alive': 'False' - } @staticmethod def cookies2dict(source_str: str): @@ -193,11 +184,12 @@ class PtSpider: json: dict = None, timeout: int = 30, delay: int = 15, - headers: dict = {}, proxies: dict = None): site = my_site.site scraper = self.get_scraper(delay=delay) - self.headers = headers + self.headers = { + 'User-Agent': my_site.user_agent, + } for k, v in eval(site.sign_in_headers).items(): self.headers[k] = v # logger.info(self.headers)