53 lines
1.1 KiB
Python
53 lines
1.1 KiB
Python
|
|
import time
|
|
|
|
|
|
from DrissionPage import ChromiumPage, ChromiumOptions
|
|
|
|
|
|
class WebProcess:
|
|
def __init__(self, port):
|
|
|
|
self.page = None
|
|
self.port = port
|
|
|
|
# 文件设置
|
|
path = "C:\\haha"
|
|
self.tmp_path = path + f"\\tmp_{self.port}"
|
|
self.user_path = path + f"\\user_{self.port}"
|
|
self.cache_path = path + f"\\cache_{self.port}"
|
|
|
|
def get_page_tab(self, url):
|
|
while True:
|
|
try:
|
|
tab = self.page.get_tab(url=url)
|
|
return tab
|
|
except:
|
|
time.sleep(1)
|
|
|
|
def action(self):
|
|
co = ChromiumOptions()
|
|
|
|
co.set_local_port(self.port)
|
|
co.add_extension(r'3.65.22_0')
|
|
|
|
# co.set_tmp_path(self.tmp_path)
|
|
# co.set_user_data_path(self.user_path)
|
|
# co.set_cache_path(self.cache_path)
|
|
|
|
self.page = ChromiumPage(addr_or_opts=co)
|
|
|
|
try:
|
|
|
|
time.sleep(10000)
|
|
except:
|
|
pass
|
|
|
|
finally:
|
|
self.page.quit()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
web_process = WebProcess(port=1002)
|
|
web_process.action()
|