修复.和#查询语句失效问题

This commit is contained in:
g1879 2020-11-20 17:34:52 +08:00
parent acdc4f56e1
commit a5f3fee652

View File

@ -10,6 +10,7 @@ from pathlib import Path
from re import split as re_SPLIT from re import split as re_SPLIT
from shutil import rmtree from shutil import rmtree
from typing import Union from typing import Union
from zipfile import ZipFile
from lxml.html import HtmlElement from lxml.html import HtmlElement
from selenium.webdriver.remote.webelement import WebElement from selenium.webdriver.remote.webelement import WebElement
@ -102,15 +103,15 @@ def str_to_loc(loc: str) -> tuple:
# .和#替换为class和id查找 # .和#替换为class和id查找
if loc.startswith('.'): if loc.startswith('.'):
if loc.startswith(('.=', '.:',)): if loc.startswith(('.=', '.:',)):
loc.replace('.', '@class', 1) loc = loc.replace('.', '@class', 1)
else: else:
loc.replace('.', '@class=', 1) loc = loc.replace('.', '@class=', 1)
if loc.startswith('#'): if loc.startswith('#'):
if loc.startswith(('#=', '#:',)): if loc.startswith(('#=', '#:',)):
loc.replace('#', '@id', 1) loc = loc.replace('#', '@id', 1)
else: else:
loc.replace('#', '@id=', 1) loc = loc.replace('#', '@id=', 1)
# 根据属性查找 # 根据属性查找
if loc.startswith('@'): if loc.startswith('@'):
@ -281,3 +282,12 @@ def clean_folder(folder_path: str, ignore: list = None) -> None:
f.unlink() f.unlink()
elif f.is_dir(): elif f.is_dir():
rmtree(f, True) rmtree(f, True)
def unzip(zip_path: str, to_path: str) -> Union[list, None]:
"""解压下载的chromedriver.zip文件"""
if not zip_path:
return
with ZipFile(zip_path, 'r') as f:
return [f.extract(f.namelist()[0], path=to_path)]