mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
4.0.0b7当set_headless(False)但接管了无头浏览器,将起关闭并启动新的有头浏览器;prop()改用js方式
This commit is contained in:
parent
f850760651
commit
a5e86167e2
@ -76,6 +76,7 @@ def get_launch_args(opt):
|
|||||||
elif i.startswith('--headless'):
|
elif i.startswith('--headless'):
|
||||||
if i == '--headless=false':
|
if i == '--headless=false':
|
||||||
headless = False
|
headless = False
|
||||||
|
continue
|
||||||
elif i == '--headless':
|
elif i == '--headless':
|
||||||
i = '--headless=new'
|
i = '--headless=new'
|
||||||
headless = True
|
headless = True
|
||||||
|
@ -369,14 +369,11 @@ class ChromiumElement(DrissionElement):
|
|||||||
:param prop: 属性名
|
:param prop: 属性名
|
||||||
:return: 属性值文本
|
:return: 属性值文本
|
||||||
"""
|
"""
|
||||||
p = self.page.run_cdp('Runtime.getProperties', objectId=self._obj_id)['result']
|
try:
|
||||||
for i in p:
|
value = self.run_js(f'return this.{prop};')
|
||||||
if i['name'] == prop:
|
|
||||||
if 'value' not in i or 'value' not in i['value']:
|
|
||||||
return None
|
|
||||||
|
|
||||||
value = i['value']['value']
|
|
||||||
return format_html(value) if isinstance(value, str) else value
|
return format_html(value) if isinstance(value, str) else value
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def run_js(self, script, *args, as_expr=False):
|
def run_js(self, script, *args, as_expr=False):
|
||||||
"""对本元素执行javascript代码
|
"""对本元素执行javascript代码
|
||||||
|
@ -71,10 +71,8 @@ class ChromiumPage(ChromiumBase):
|
|||||||
ws = ws.json()['webSocketDebuggerUrl'].split('/')[-1]
|
ws = ws.json()['webSocketDebuggerUrl'].split('/')[-1]
|
||||||
self._browser = Browser(self._driver_options.debugger_address, ws, self)
|
self._browser = Browser(self._driver_options.debugger_address, ws, self)
|
||||||
|
|
||||||
print(is_exist, self._driver_options._headless, self._browser.run_cdp('Browser.getVersion')['userAgent'])
|
|
||||||
if (is_exist and self._driver_options._headless is False and
|
if (is_exist and self._driver_options._headless is False and
|
||||||
'headless' in self._browser.run_cdp('Browser.getVersion')['userAgent'].lower()):
|
'headless' in self._browser.run_cdp('Browser.getVersion')['userAgent'].lower()):
|
||||||
print('aaa')
|
|
||||||
self._browser.quit(3)
|
self._browser.quit(3)
|
||||||
connect_browser(self._driver_options)
|
connect_browser(self._driver_options)
|
||||||
ws = get(f'http://{self._driver_options.debugger_address}/json/version', headers={'Connection': 'close'})
|
ws = get(f'http://{self._driver_options.debugger_address}/json/version', headers={'Connection': 'close'})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user