mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
优化cookies域名设置;提高检查端口可用性速度
This commit is contained in:
parent
0d141e66b8
commit
c708a80c6c
@ -1004,7 +1004,12 @@ class ChromiumBaseSetter(object):
|
|||||||
result_cookies = []
|
result_cookies = []
|
||||||
for cookie in cookies:
|
for cookie in cookies:
|
||||||
if not cookie.get('domain', None):
|
if not cookie.get('domain', None):
|
||||||
cookie['domain'] = urlparse(self._page.url).netloc
|
netloc = urlparse(self._page.url).netloc
|
||||||
|
if netloc.replace('.', '').isdigit(): # ip
|
||||||
|
cookie['domain'] = netloc
|
||||||
|
else: # 域名
|
||||||
|
u = netloc.split('.')
|
||||||
|
cookie['domain'] = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else netloc
|
||||||
result_cookies.append({'value': '' if cookie['value'] is None else cookie['value'],
|
result_cookies.append({'value': '' if cookie['value'] is None else cookie['value'],
|
||||||
'name': cookie['name'],
|
'name': cookie['name'],
|
||||||
'domain': cookie['domain']})
|
'domain': cookie['domain']})
|
||||||
|
@ -291,7 +291,7 @@ class WebPageTab(SessionPage, ChromiumTab):
|
|||||||
domain = netloc
|
domain = netloc
|
||||||
else: # 域名
|
else: # 域名
|
||||||
u = netloc.split('.')
|
u = netloc.split('.')
|
||||||
domain = f'{u[-2]}.{u[-1]}' if len(u) > 1 else netloc
|
domain = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else netloc
|
||||||
cookies = []
|
cookies = []
|
||||||
for cookie in super().get_cookies():
|
for cookie in super().get_cookies():
|
||||||
if not cookie.get('domain', None):
|
if not cookie.get('domain', None):
|
||||||
|
@ -120,6 +120,7 @@ def port_is_using(ip, port):
|
|||||||
"""
|
"""
|
||||||
from socket import socket, AF_INET, SOCK_STREAM
|
from socket import socket, AF_INET, SOCK_STREAM
|
||||||
s = socket(AF_INET, SOCK_STREAM)
|
s = socket(AF_INET, SOCK_STREAM)
|
||||||
|
s.settimeout(.1)
|
||||||
result = s.connect_ex((ip, int(port)))
|
result = s.connect_ex((ip, int(port)))
|
||||||
s.close()
|
s.close()
|
||||||
return result == 0
|
return result == 0
|
||||||
|
@ -272,7 +272,7 @@ class Drission(object):
|
|||||||
cookie_domain = browser_domain
|
cookie_domain = browser_domain
|
||||||
else: # 域名
|
else: # 域名
|
||||||
u = browser_domain.split('.')
|
u = browser_domain.split('.')
|
||||||
cookie_domain = f'{u[-2]}.{u[-1]}' if len(u) > 1 else browser_domain
|
cookie_domain = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else browser_domain
|
||||||
else:
|
else:
|
||||||
raise ValueError('cookie中没有域名或浏览器未访问过URL。')
|
raise ValueError('cookie中没有域名或浏览器未访问过URL。')
|
||||||
|
|
||||||
@ -336,7 +336,7 @@ class Drission(object):
|
|||||||
domain = ex_url
|
domain = ex_url
|
||||||
else: # 域名
|
else: # 域名
|
||||||
u = ex_url.split('.')
|
u = ex_url.split('.')
|
||||||
domain = f'{u[-2]}.{u[-1]}' if len(u) > 1 else ex_url
|
domain = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else ex_url
|
||||||
|
|
||||||
cookies = []
|
cookies = []
|
||||||
for cookie in self.session.cookies:
|
for cookie in self.session.cookies:
|
||||||
|
@ -215,7 +215,7 @@ class SessionPage(BasePage):
|
|||||||
domain = netloc
|
domain = netloc
|
||||||
else: # 域名
|
else: # 域名
|
||||||
u = netloc.split('.')
|
u = netloc.split('.')
|
||||||
domain = f'{u[-2]}.{u[-1]}' if len(u) > 1 else netloc
|
domain = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else netloc
|
||||||
cookies = tuple(x for x in self.session.cookies if domain in x.domain or x.domain == '')
|
cookies = tuple(x for x in self.session.cookies if domain in x.domain or x.domain == '')
|
||||||
else:
|
else:
|
||||||
cookies = tuple(x for x in self.session.cookies)
|
cookies = tuple(x for x in self.session.cookies)
|
||||||
|
@ -195,7 +195,7 @@ class SessionPage(BasePage):
|
|||||||
domain = netloc
|
domain = netloc
|
||||||
else: # 域名
|
else: # 域名
|
||||||
u = netloc.split('.')
|
u = netloc.split('.')
|
||||||
domain = f'{u[-2]}.{u[-1]}' if len(u) > 1 else netloc
|
domain = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else netloc
|
||||||
cookies = tuple(x for x in self.session.cookies if domain in x.domain or x.domain == '')
|
cookies = tuple(x for x in self.session.cookies if domain in x.domain or x.domain == '')
|
||||||
else:
|
else:
|
||||||
cookies = tuple(x for x in self.session.cookies)
|
cookies = tuple(x for x in self.session.cookies)
|
||||||
|
@ -365,7 +365,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
domain = netloc
|
domain = netloc
|
||||||
else: # 域名
|
else: # 域名
|
||||||
u = netloc.split('.')
|
u = netloc.split('.')
|
||||||
domain = f'{u[-2]}.{u[-1]}' if len(u) > 1 else netloc
|
domain = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else netloc
|
||||||
cookies = []
|
cookies = []
|
||||||
for cookie in super().get_cookies():
|
for cookie in super().get_cookies():
|
||||||
if not cookie.get('domain', None):
|
if not cookie.get('domain', None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user