修复re没有适配换行问题

This commit is contained in:
g1879 2023-12-15 16:52:53 +08:00
parent 7284b108ef
commit 35c25fa454
4 changed files with 7 additions and 5 deletions

View File

@ -266,7 +266,7 @@ def raise_error(r):
'No node with given id found', 'Node with given id does not belong to the document',
'No node found for given backend id'):
raise ElementLostError
elif error == 'tab closed':
elif error == ('tab closed', 'No target with given id found'):
raise PageClosedError
elif error == 'timeout':
raise TimeoutError

View File

@ -172,6 +172,8 @@ class ChromiumBase(BasePage):
except:
if self._debug:
print('获取文档失败。')
from traceback import print_exc
print_exc()
print('请把报错信息和重现方法告知作者,感谢。\nhttps://gitee.com/g1879/DrissionPage/issues/new')
raise
# return False

View File

@ -4,7 +4,7 @@
@Contact : g1879@qq.com
"""
from copy import copy
from re import search, findall
from re import search, findall, DOTALL
from time import sleep, perf_counter
from .._elements.chromium_element import ChromiumElement
@ -304,7 +304,7 @@ class ChromiumFrame(ChromiumBase):
"""返回元素outerHTML文本"""
tag = self.tag
out_html = self._target_page.run_cdp('DOM.getOuterHTML', backendNodeId=self.frame_ele._backend_id)['outerHTML']
sign = search(rf'<{tag}.*?>', out_html).group(0)
sign = search(rf'<{tag}.*?>', out_html, DOTALL).group(0)
return f'{sign}{self.inner_html}</{tag}>'
@property

View File

@ -4,7 +4,7 @@
@Contact : g1879@qq.com
"""
from pathlib import Path
from re import search
from re import search, DOTALL
from time import sleep
from urllib.parse import urlparse, quote
@ -379,7 +379,7 @@ def set_charset(response):
# 在headers中获取不到编码且如果是网页
elif content_type.replace(' ', '').startswith('text/html'):
re_result = search(b'<meta.*?charset=[ \\\'"]*([^"\\\' />]+).*?>', response.content)
re_result = search(b'<meta.*?charset=[ \\\'"]*([^"\\\' />]+).*?>', response.content, DOTALL)
if re_result:
charset = re_result.group(1).decode()